-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.cs
More file actions
61 lines (60 loc) · 1.62 KB
/
Copy pathCode.cs
File metadata and controls
61 lines (60 loc) · 1.62 KB
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
namespace hackAssembler;
public class Code
{
static public string Dest(string field)
{
return field switch
{
"null" => "000",
"M" => "001",
"D" => "010",
"MD" => "011",
"A" => "100",
"AM" => "101",
"AD" => "110",
"AMD" => "111",
_ => "UNKNOWN DEST",
};
}
static public string Comp(string field)
{
return field switch
{
"0" => "101010",
"1" => "111111",
"-1" => "111010",
"D" => "001100",
"A" or "M" => "110000",
"!D" => "001101",
"!A" or "!M" => "110001",
"-D" => "001111",
"-A" or "-M" => "110011",
"D+1" => "011111",
"A+1" or "M+1" => "110111",
"D-1" => "001110",
"A-1" or "M-1" => "110010",
"D+A" or "D+M" => "000010",
"D-A" or "D-M" => "010011",
"A-D" or "M-D" => "000111",
"D&A" or "D&M" => "000000",
"D|A" or "D|M" => "010101",
_ => "UNKNOWN COMP",
};
;
}
static public string Jump(string field)
{
return field switch
{
"null" => "000",
"JGT" => "001",
"JEQ" => "010",
"JGE" => "011",
"JLT" => "100",
"JNE" => "101",
"JLE" => "110",
"JMP" => "111",
_ => "UNKNOWN JUMP"
};
}
}