Notes on the CPU Emulator
-
11/28
For more in-depth information
about the test script file format
(*.tst)
refer to
the Appendix B of the nand2tetris book.
-
11/24
How to implement “RAM[RAM[x]] = RAM[y]”?
@y
D=M
@x
A=M
M=D
-
11/23
The test script file
Mult.asm
works as follows.
- Set the operands
(RAM[R0] and RAM[R1]).
- Run the program for some
time (repeat xxx)
- Print the output (RAM[R0],
RAM[R1],
RAM[R2])
Therefore,
if your program doesn't finish all the computations
within the number of clocks (the value after repeat)
the CPUEmulator may conclude that your program
is incorrect.
If you
think this is the case, just
increase the number of clocks for
that test.
(Note that this may increase the running time.)
-
11/22
How to implement
“RAM[z]=RAM[x]+RAM[y]”?
@x
D=M
@y
D=D+M
@z
M=D
-
11/22
To pass a negative constant value.
(We can pass only a positive value
using an A-instruction
due to its 15-bit limit.)
Example: to store -123 in RAM[x].
@123
D=-A
@x
M=D
-
11/22
(For MacOS users)
You should install the Java SDK
(not the JRE)
version ≥1.8
here
to make the screen work correctly.
Refer to
this page for more information.