Instruction Summary · Running the Simulator
| Instruction | Action | Example | 
|---|---|---|
| 0000  Halt | Halt | 0000 Halt | 
| 1dab  Add | Rd  Ra + Rb | 1012 R0  R1 + R2 | 
| 2dab  Subtract | Rd  Ra - Rb | 2113 R1  R1 - R3 | 
| 3dab  Multiply | Rd  Ra × Rb | 3266 R2  R6 × R6 | 
| 4d0x  System call | Code x, parameter in Rd | 4602 Print R6 | 
| 50xx  Jump | PC  xx | 508B Jump to 8B | 
| 6dxx  Jump if less | If Rd <0 then PC xx | 628B If R2 <0 then jump to 8B | 
| 7d00  Jump indirect | PC  Rd | 7300 PC  R3 | 
| 8dxx  Jump and link | Rd  PC, PC <-xx | 848B R4  PC, jump to 8B | 
| 9dax  Load | Rd  M[Ra+x] | 9301 Load M[R0+1] into R3 | 
| Adax  Store | M[Ra+x]  Rd | A412 Store R4 into M[R1+2] | 
| Bdxx  Load immediate | Rd  xx | B50A Set R5 to 10 decimal | 
| Cdab  Exclusive OR | Rd  Ra ^ Rb | C512 R5  R1 ^ R2 | 
| Ddab  AND | Rd  Ra & Rb | D645 R6  R4 & R5 | 
| Edab  Right shift | Rd  Ra >>Rb | E056 R0  R5 >>R6 | 
| Fdab  Left shift | Rd  Ra <<Rb | F764 R7  R6 <<R4 | 
/u/cs126/bin/toy simulates the TOY machine. To run it, use a
command of the form
/u/cs126/bin/toy[ option | file ]...
toy loads and executes the TOY program in each of its file
arguments, or loads and executes the TOY program in the standard input if there
are no file arguments. After execution of each file, toy
prints a dump of the registers and the nonzero 8-word blocks of memory on the
standard error output.
Before toy loads the contents of a file argument, it
clears memory and the registers. Lines in file arguments that begin
xx
:yyyy
where xx and yyyy are hexadecimal numbers initialize memory location xx to yyyy. Lines that begin with just xx establish xx as the starting address. Memory initializations and starting addresses may occur in any order. Repeated occurrences of starting addresses or memory initializations are accepted and overwrite previous values. Trailing characters on these lines and all other lines are treated as comments. For examples, see /u/cs126/toy.
The -l option causes toy to print a "load
trace" as it loads file into memory.
The -t option causes toy to trace the execution
of the TOY programs. For each instruction, it  prints a line on the standard
error output giving the PC and summarizing the instruction and its result.
The -s option causes toy to execute instructions
one-at-a-time and prompt for an option after executing each instruction. The
prompt is
/u/cs126/bin/toy> [cdqts^Dh?]
Responding with an h or ? elicits a list of
responses and actions and another prompt:
c or Enter continue d dump t toggle tracing s toggle stepping q quit (no dump) ^D dump and quit h or ? this message /u/cs126/bin/toy> [cdqts^Dh?]
A newline or c continues execution; d, t,
or s prints a dump, toggles tracing, or toggles stepping, and
reprompts. q terminates execution and Ctrl-D prints a dump then
terminates. -s is usually used with -t.
Both options are toggles: They turn on the option if it's off and vice versa.
The source code for the simulator is in /u/cs126/toy/toy.c.