-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup_table.rb
66 lines (62 loc) · 1.08 KB
/
lookup_table.rb
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
TABLE_C_A0 = {
'0' => 0b101010,
'1' => 0b111111,
'-1' => 0b111010,
'D' => 0b001100,
'A' => 0b110000,
'!D' => 0b001101,
'!A' => 0b110001,
'-D' => 0b001111,
'-A' => 0b110011,
'D+1' => 0b011111,
'A+1' => 0b110111,
'D-1' => 0b001110,
'A-1' => 0b110010,
'D+A' => 0b000010,
'D-A' => 0b010011,
'A-D' => 0b000111,
'D&A' => 0b000000,
'D|A' => 0b010101
}
TABLE_C_A1 = {
'M' => 0b110000,
'!M' => 0b110001,
'-M' => 0b110011,
'M+1' => 0b110111,
'M-1' => 0b110010,
'D+M' => 0b000010,
'M+D' => 0b000010,
'D-M' => 0b010011,
'M-D' => 0b000111,
'D&M' => 0b000000,
'D|M' => 0b010101
}
TABLE_D = {
nil => 0b000,
'M' => 0b001,
'D' => 0b010,
'MD' => 0b011,
'A' => 0b100,
'AM' => 0b101,
'AD' => 0b110,
'AMD' => 0b111
}
TABLE_J = {
nil => 0b000,
'JGT' => 0b001,
'JEQ' => 0b010,
'JGE' => 0b011,
'JLT' => 0b100,
'JNE' => 0b101,
'JLE' => 0b110,
'JMP' => 0b111
}
TABLE_P = {
'SCREEN' => 0x4000,
'KBD' => 0x6000,
'SP' => 0,
'LCL' => 1,
'ARG' => 2,
'THIS' => 3,
'THAT' => 4
}