-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
codecyang
committed
Jul 9, 2020
1 parent
cbc3654
commit 3902c3c
Showing
6 changed files
with
124 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Assembler | ||
|
||
### Compile | ||
|
||
``` | ||
javac Assembler.java | ||
``` | ||
|
||
|
||
### Usage | ||
|
||
``` | ||
java Assembler assembly_program.asm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.util.HashMap; | ||
|
||
class SymbolTable{ | ||
private HashMap<String, Integer> symbolTable = new HashMap<>(); | ||
|
||
private static final String[] defaultSymbol = { | ||
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", | ||
"R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15", | ||
"SCREEN", "KBD", | ||
"SP", "LCL", "ARG", "THIS", "THAT" | ||
}; | ||
|
||
private static final int[] defaultSymbolValues = { | ||
0, 1, 2, 3, 4, 5, 6, 7, | ||
8, 9, 10, 11, 12, 13, 14, 15, | ||
16384, 24576, | ||
0, 1, 2, 3, 4 | ||
}; | ||
|
||
SymbolTable(){ | ||
for(int i = 0 ; i < defaultSymbol.length ; i++) | ||
symbolTable.put(defaultSymbol[i], defaultSymbolValues[i]); | ||
} | ||
|
||
void addEntry(String symbol, int address){ | ||
symbolTable.put(symbol, address); | ||
} | ||
|
||
boolean contains(String symbol){ | ||
return symbolTable.containsKey(symbol); | ||
} | ||
|
||
int getAddress(String symbol){ | ||
return symbolTable.get(symbol); | ||
} | ||
} |