-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.txt
83 lines (71 loc) · 2.33 KB
/
spec.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
hack is set up as follows:
2 16-bit registers, A and D.
D is a data register
A can be used for data or addresses
Instruction memory stores instructions
It has addresses of 15 bits and holds 16-bit words
Instruction memory is read-only
Data memory stores data (duh)
Like instruction memory, it has 15-bit addresses and 16-bit words
Data memory is writable
Implicit things abound, oh joys
Since data memory uses 15-bit addresses, we load an address into A
And we alias the register M to refer to Memory[A]
Similarly, we use A for direct memory access to instruction memory
So if we wanted to jump to instruction memory 35,
We load 35 into A, and then do a blank GOTO
This jumps to InstructionMemory[A]
Finally, we have the special syntax @value
value can be either a literal integer or a name
This is a load instruction; it assigns value to A
This syntax is called an A-instruction.
The op code is 0vvv vvvv vvvv vvvv
Where vvv vvvv vvvv vvvv is the binary representation of value
C-instructions do actual computation
In general, dest=comp;jump
dest may be empty, in which case the = is omitted
jump may be empty, in which case the ; is omitted
The op code is 111a cccc ccdd djjj
a is a flag for the type of instruction
cccc cc is a code for computation
full table in pdf
when a=0
opcode result
101010 0
111111 1
111010 -1
001100 D
110000 A
001101 !D
110001 !A
001111 -D
110011 -A
011111 D+1
110111 A+1
001110 D-1
110010 A-1
000010 D+A
010011 D-A
000111 A-D
000000 D&A (logical AND)
010101 D|A (logical OR)
when a=1, replace all instances of 'A' with 'M'
dd d is a code for which location to store the value
first bit on to store to A
second bit on to store to D
third bit on to store to M --> recall, M = Memory[A]
Any or all of these may be set
jjj is a code for the condition on which to jump to InstructionMemory[A]
first bit on to jump if output of computation is < 0
second bit on to jump if output of computation is = 0
third bit on to jump if output of computation is > 0
Some predefined symbols:
Virtual registers R0 - R15 point to RAM[0] - RAM[15]
SP points at RAM[0]
LCL points at RAM[1]
ARG points at RAM[2]
THIS points at RAM[3]
THAT points at RAM[4]
Labels are defined with (labelname)
Variables are automatically assigned a RAM location, starting at RAM[16]
I/O handling also exists, we'll get to that later