Instruction Summary · Running the Simulator
Instruction | Action | Example |
---|---|---|
0000Halt | Halt | 0000 Halt |
1dabAdd | Rd Ra + Rb | 1012 R0 R1 + R2 |
2dabSubtract | Rd Ra - Rb | 2113 R1 R1 - R3 |
3dabMultiply | Rd Ra × Rb | 3266 R2 R6 × R6 |
4d0xSystem call | Code x, parameter in Rd | 4602 Print R6 |
50xxJump | PC xx | 508B Jump to 8B |
6dxxJump if less | If Rd < 0 then PC
xx |
628B If R2 < 0 then jump to 8B |
7d00Jump indirect | PC Rd | 7300 PC R3 |
8dxxJump and link | Rd
PC, PC <- xx |
848B R4 PC, jump to 8B |
9daxLoad | Rd M[Ra+x] | 9301 Load M[R0+1] into R3 |
AdaxStore | M[Ra+x] Rd | A412 Store R4 into M[R1+2] |
BdxxLoad immediate | Rd xx | B50A Set R5 to 10 decimal |
CdabExclusive OR | Rd Ra ^ Rb | C512 R5 R1 ^ R2 |
DdabAND | Rd Ra & Rb | D645 R6 R4 & R5 |
EdabRight shift | Rd
Ra >> Rb |
E056 R0
R5 >> R6 |
FdabLeft 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
.