This is an assembler for A-instruction and C-instruction.
This assembler is for course nand2tetirs programming assignment.
java -jar assemble.jar file.asm
- The input file path should end with .asm
- The target file will end with .hack
- A register
A
: the register holding an address - D register
D
: the register holding data - M register
M
: the virtual register holding the data in memory located by A register - symbol: the string representing variable or label; it should not be a string of which all characters are digits
-
Comment
- single line comment
//<comments>
- single line comment
-
Label
- grammar:
(<label>)
<label>
is asymbol
- semantics
- add a lable for conviniently jump
- grammar:
-
A instruction
- grammar:
@<value>
<value>
is asymbol
- semantics
- load
<value>
to address registerA
<value>
can be a deciaml integer in[0,16641)
<value>
can be alabel
orvariable
- load
- grammar:
-
C instruction
- grammar:
<destination>=<computation>[;<jump>]
or[<destination>=]<computation>;<jump>
<destination>
:A|D|M|AD|AM|MD|ADM
<computation>
: see Computations<jump>
: see Jump Conditions
- semantics:
- load the result of
<computation>
to<destination>
; if the result meets condition<jump>
, the address of next instruction will be the one stored inA
- load the result of
- grammar:
A computations | M computations |
---|---|
0 | |
1 | |
-1 | |
D | |
A | M |
!D | |
!A | !M |
-D | |
-A | -M |
D+1 | |
A+1 | M+1 |
D-1 | |
A-1 | M-1 |
D+A | D+M |
D-A | D-M |
A-D | M-D |
D&A | D&M |
D|A | D|M |
<jump> | description |
---|---|
JMP | jump without any condition |
JEQ | jump when the result is 0 |
JNE | jump when the result is not 0 |
JGT | jump when the result is greater than 0 |
JLT | jump when the result is less than 0 |
JGE | jump when the result is greater than or equal to 0 |
JLE | jump when the result is less than or equal to 0 |