Goals


Checklist

  • Use the submit command: /u/cs126/bin/submit 5 readme toy.c option.toy. Do not use different file names.

  • readme
  • Name, precept number.
  • Provide high level description of code and list any problems encountered.
  • Output of your TOY program, including the initial and final "core dump" (print out a running count of the number times that your option is in the money after each of the 255 simulations).
  • Indicate whatever help (if any) you received.
  • executing
  • compile toy.c with lcc and type a.out < option.toy
  • toy.c
  • Available at /u/cs126/code/toy.c. Compile with lcc since the file uses // for commenting.
  • Detailed notes on the TOY machine are availabe from the Lectures page.
  • option.toy
  • You may start from the TOY program /u/cs126/code/bits.toy which prints out 30 pseudo-random bits. Pay careful attention to the mechanics of a "for-loop" since you will have to write one later.
  • You will want to remove the print statement that displays each random bit - this will ultimately produce 30 * 255 lines of output, which aren't very useful.
  • Now, add code to perform 1 experiment.
  • Next add code to perform the experiment 255 times.
  • Using the LFBSR to generate pseudo-random bits, the option will be in the money 49 of 255 times. This provides a good approximation to the mathematical expected value of 194129627/1073741824 or roughly 18%. Part of the inaccuracy is due to performing only 255 trials; the rest could be fixed by a better pseudo-random number generator.
  • TOY debugging hints
  • Comment your TOY code. Update your comments if you modify your code.
  • Remember that all values, "line numbers", and arithmetic are in hex. This is by far the most common error.
  • You have only 8 registers to work with, so you may need to use some registers for multiple purposes. All registers are gloabal variables, so be careful.
  • Check the initial "core dump" to be sure that your program was read in correctly. This will fix common errors like having two or more instructions with the same line number, or forgetting the colon after the memory address.
  • Watch out for jump statements - if you insert a new line of code between existsing lines, the location that you want to jump to may change. A common mistake is to update only the "comments", not the actual instructions. Also, after updating the line numbers, check that there are no inadvertent "gaps" in line numbering.
  • Be careful to use consecutive "line numbers" - if you don't specify the initial contents of some memory address, it is set to 0000 which means halt. You may use "dummy" instructions as in the TOY notes.
  • Use opcode 4 to print out the value of a particular register. This is the analog of printf debugging in C.
  • Add extra dump() and dumpreg() commands in your TOY simulator to print out the contents of the pc, memory, and registers, as necessary. Remove these before submitting toy.c.



  • Kevin Wayne