-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.cs
More file actions
41 lines (36 loc) · 1.11 KB
/
Copy pathSymbolTable.cs
File metadata and controls
41 lines (36 loc) · 1.11 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
namespace hackAssembler;
public class SymbolTable
{
private Dictionary<string, int> _table = new();
public SymbolTable()
{
// initializing the table with the predefined Symbols
_table.Add("R0", 0);
_table.Add("R1", 1);
_table.Add("R2", 2);
_table.Add("R3", 3);
_table.Add("R4", 4);
_table.Add("R5", 5);
_table.Add("R6", 6);
_table.Add("R7", 7);
_table.Add("R8", 8);
_table.Add("R9", 9);
_table.Add("R10", 10);
_table.Add("R11", 11);
_table.Add("R12", 12);
_table.Add("R13", 13);
_table.Add("R14", 14);
_table.Add("R15", 15);
_table.Add("SP", 0);
_table.Add("LCL", 1);
_table.Add("ARG", 2);
_table.Add("THIS", 3);
_table.Add("THAT", 4);
_table.Add("SCREEN", 16384);
_table.Add("KBD", 24576);
}
public void AddEntry(string symbol, int address)
=> _table.Add(symbol, address);
public Boolean Contains(string symbol) => _table.ContainsKey(symbol);
public int GetAddress(string symbol) => _table[symbol];
}