Preparation

  • Review the TOY lecture notes and also the more detailed Notes on TOY.

  • option.toy

    For this assignment you will write a TOY machine language program. You will not have to write any C code.

  • Here's a few hints for getting started.

  • Step 0. Write pseudocode on paper (or write an analogous C program), and figure out which registers will get used for each task.

  • Step 1. Design bits.toy so that it performs 1 experiment. Initialize one register, say register 4, to the hex equivalent of $128. Then increment or decrement register 4 thirty times, depending on the value read in from standard input.

  • Step 2. Determine the value of the option: it is the maximum of 0 and R[4] - 133. You will probably want to use the jump if positive instruction. Note that this instruction branches if the register is holding a positive value (i.e., not zero or a two's complement negative integer).

  • Step 3. Repeat this experiment 100 times. An estimate of the option's expected value is the last value divided by 100. Note: you are not required to write TOY code to compute this value.

  • Debugging Hints

    Here are some debugging hints that may help you out.

  • Remember that all values, "line numbers", and arithmetic are in hex. This is by far the most common error.

  • The pc is initially set to 10, so the first instruction of your TOY program must be at memory address 10.

  • Comment your TOY code. Also, this may sound silly, but don't accidentally update your comments and forget to update the actual code!

  • All registers are global variables, so be careful.

  • Watch out for jump statements - if you insert a new line of code between existing lines, the location that you want to jump to may change. Also, after updating the line numbers, check that there are no inadvertent "gaps" in line numbering. You need to be careful to use consecutive "line numbers", since 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.

  • Check that the initial "core dump" matches the program you intended to input. This will help you spot missing, duplicate, or incorrectly formatted instructions.



  • Kevin Wayne