Goals

  • Simulate the behavior of a stock using a random walk.

  • Learn to program in the TOY machine language.

  • Appreciate the programming and debugging advantages of a structured programming language over machine language!

  • Learn about command-line inputs and piping.

  • Avoid killing you during midterms week. :)

  • TOY simulators

    To run your program, you will want to use one of the following TOY simulators. We recommend that you use the C TOY Simulator as we will be grading with that one. However, you are free to develop your code on the Visual X-TOY simulator.

  • The TOY simulator in C from lecture is available at /u/cs126/files/toy/. To use the simulator, do the following:

  • Compile the simulator with:
    gcc126 toy.c
    
    If you are using Unix, rename your executable file via:
    mv a.out toy
    
    Test it by typing:
    toy multiply.toy
    
    The TOY program expects you to enter two integers from stdin. It outputs their product to stdout. The simulator also displays a core dump of all registers, main memory, and the program counter before and after the program executes.
  • The Visual X-TOY simulator from lecture provides lots of useful development features.

  • Pseduo-random Bits

    To generate pseudo-random bits, use the program /u/cs126/files/toy/bits.c.

  • Compile it with:
    gcc126 bits.c
    
    If you are using Unix, rename your executable file via:
    mv a.out bits
    

  • Test it with the command
    bits
    
    You should see 3000 pseudo-random bits whiz by your screen. If you want to experiment with different bits, change the seed value by supplying an optional command-line argument.
    bits 1234
    

  • To connect the output of the pseduo-random bit generator to the input of the TOY simulator, combine piping with command line input:
    bits | toy option.toy
    

  • Checking your work and hints

  • Here are some hints for getting started and debugging.

  • Here are the cumulative profits after each experiment that your final program should print out. An estimate of the option's expected value is the last value divided by 100.

  • Submission and readme

  • Submit the following files:
    readme.txt option.toy
    
    Do not use different file names.

  • Your option.toy program should be amply commented. It should also be cleaned up so that the only call to standard output is to print out the 100 successive sums (the ith successive sum is the cumulative profit obtained in the first i option experiments). You will lose points if you don't follow these instructions.

  • The readme.txt file should contain the following information. Here is a readme template.

  • Name, precept number.

  • High level description of code, any serious problems you encountered, and whatever outside help that you received.

  • Include a table indicating what each of the registers are used for.

  • Give your estimate of the value of 1 option in dollars and cents. Use pencil and paper to do the division. (If you feel adventuresome, feel free to write TOY code to do it.)

  • Indicate whether you used the C or Java TOY simulator to develop your code.



  • Kevin Wayne