Instruction Summary · Running the Simulator
Instruction | Action | Example |
---|---|---|
0000![]() |
Halt | 0000 Halt |
1dab![]() |
Rd
![]() |
1012 R0
![]() |
2dab![]() |
Rd
![]() |
2113 R1
![]() |
3dab![]() |
Rd
![]() |
3266 R2
![]() |
4d0x![]() |
Code x, parameter in Rd | 4602 Print R6 |
50xx![]() |
PC
![]() |
508B Jump to 8B |
6dxx![]() |
If Rd < 0 then PC
![]() |
628B If R2 < 0 then jump to 8B |
7d00![]() |
PC
![]() |
7300 PC
![]() |
8dxx![]() |
Rd
![]() <- xx |
848B R4
![]() |
9dax![]() |
Rd
![]() |
9301 Load M[R0+1] into R3 |
Adax![]() |
M[Ra+x]
![]() |
A412 Store R4 into M[R1+2] |
Bdxx![]() |
Rd
![]() |
B50A Set R5 to 10 decimal |
Cdab![]() |
Rd
![]() |
C512 R5
![]() |
Ddab![]() |
Rd
![]() |
D645 R6
![]() |
Edab![]() |
Rd
![]() >> Rb |
E056 R0
![]() >> R6 |
Fdab![]() |
Rd
![]() << Rb |
F764 R7
![]() << 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
.