File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1
1
module Code
2
+ module_function
3
+
4
+ def dest ( mnemonic )
5
+ {
6
+ '' => '000' ,
7
+ 'M' => '001' ,
8
+ 'D' => '010' ,
9
+ 'MD' => '011' ,
10
+ 'A' => '100' ,
11
+ 'AM' => '101' ,
12
+ 'AD' => '110' ,
13
+ 'AMD' => '111'
14
+ } . fetch ( mnemonic )
15
+ end
16
+
17
+ def comp ( mnemonic )
18
+ {
19
+ '0' => '0101010' ,
20
+ '1' => '0111111' ,
21
+ '-1' => '0111010' ,
22
+ 'D' => '0001100' ,
23
+ 'A' => '0110000' ,
24
+ '!D' => '0001101' ,
25
+ '!A' => '0110001' ,
26
+ '-D' => '0001111' ,
27
+ '-A' => '0110011' ,
28
+ 'D+1' => '0011111' ,
29
+ 'A+1' => '0110111' ,
30
+ 'D-1' => '0001110' ,
31
+ 'A-1' => '0110010' ,
32
+ 'D+A' => '0000010' ,
33
+ 'D-A' => '0010011' ,
34
+ 'A-D' => '0000111' ,
35
+ 'D&A' => '0000000' ,
36
+ 'D|A' => '0010101' ,
37
+ 'M' => '1110000' ,
38
+ '!M' => '1110001' ,
39
+ '-M' => '1110011' ,
40
+ 'M+1' => '1110111' ,
41
+ 'M-1' => '1110010' ,
42
+ 'D+M' => '1000010' ,
43
+ 'D-M' => '1010011' ,
44
+ 'M-D' => '1000111' ,
45
+ 'D&M' => '1000000' ,
46
+ 'D|M' => '1010101'
47
+ } . fetch ( mnemonic )
48
+ end
49
+
50
+ def jump ( mnemonic )
51
+ {
52
+ '' => '000' ,
53
+ 'JGT' => '001' ,
54
+ 'JEQ' => '010' ,
55
+ 'JGE' => '011' ,
56
+ 'JLT' => '100' ,
57
+ 'JNE' => '101' ,
58
+ 'JLE' => '110' ,
59
+ 'JMP' => '111'
60
+ } . fetch ( mnemonic )
61
+ end
2
62
end
You can’t perform that action at this time.
0 commit comments