|
|
|
# ASM SYNTAX
|
|
|
|
|
|
|
|
Grammar is described via
|
|
|
|
[McKeeman Form](https://www.crockford.com/mckeeman.html).
|
|
|
|
|
|
|
|
Instruction operands order resembles Intel syntax.
|
|
|
|
|
|
|
|
`digit(min, max)` is a representation of binary, octal,
|
|
|
|
decimal or hexadecimal integer in range `[min, max]`.
|
|
|
|
I don't want to describe grammar for integers because
|
|
|
|
it does not seem like a trivial task. Sue me.
|
|
|
|
|
|
|
|
```
|
|
|
|
asm
|
|
|
|
expressions
|
|
|
|
|
|
|
|
expressions
|
|
|
|
expression
|
|
|
|
expression '\n' expressions
|
|
|
|
|
|
|
|
expression
|
|
|
|
instruction
|
|
|
|
byte-literal
|
|
|
|
|
|
|
|
byte-literal
|
|
|
|
'BYTE' digit(0, 255)
|
|
|
|
|
|
|
|
instruction
|
|
|
|
mov
|
|
|
|
jmp
|
|
|
|
'EQ'
|
|
|
|
'GT'
|
|
|
|
'LE'
|
|
|
|
'NOT'
|
|
|
|
shift
|
|
|
|
'INC'
|
|
|
|
'DEC'
|
|
|
|
'ADD'
|
|
|
|
'SUB'
|
|
|
|
'AND'
|
|
|
|
'OR'
|
|
|
|
'XOR'
|
|
|
|
'XNOR'
|
|
|
|
'COMPL' register
|
|
|
|
'SETC' digit(0, 1)
|
|
|
|
'NOP'
|
|
|
|
'HALT'
|
|
|
|
'CLOAD' register
|
|
|
|
'ZERO' register
|
|
|
|
'DIV'
|
|
|
|
'MUL'
|
|
|
|
'SWAP'
|
|
|
|
'PRTCHK'
|
|
|
|
'PRTRD'
|
|
|
|
'PRTWR'
|
|
|
|
|
|
|
|
mov
|
|
|
|
'MOV' register ',' memory
|
|
|
|
'MOV' memory ',' register
|
|
|
|
'MOV' register-half ',' digit(0, 15)
|
|
|
|
'MOV' register ',' register
|
|
|
|
|
|
|
|
jmp
|
|
|
|
'JMP' digit(-4, 8)
|
|
|
|
'JE' digit(-4, 8)
|
|
|
|
'JNE' digit(-4, 8)
|
|
|
|
'AJMP' digit(0, 255)
|
|
|
|
'AJE' digit(0, 255)
|
|
|
|
'AJNE' digit(0, 255)
|
|
|
|
|
|
|
|
shift
|
|
|
|
'SHR'
|
|
|
|
'SHL'
|
|
|
|
'ROTR'
|
|
|
|
'ROTL'
|
|
|
|
'SHR' register ',' digit(0, 7)
|
|
|
|
'SHL' register ',' digit(0, 7)
|
|
|
|
'ROTR' register ',' digit(0, 7)
|
|
|
|
'ROTL' register ',' digit(0, 7)
|
|
|
|
|
|
|
|
register
|
|
|
|
'R0'
|
|
|
|
'R1'
|
|
|
|
|
|
|
|
memory
|
|
|
|
'[' digit(0, 15) ']'
|
|
|
|
|
|
|
|
register-half
|
|
|
|
register '.l'
|
|
|
|
register '.h'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Missing stuff
|
|
|
|
|
|
|
|
There are no labels.
|
|
|
|
We will probably implement them in future.
|
|
|
|
Or we will probably not.
|
|
|
|
|
|
|
|
## Sample program
|
|
|
|
|
|
|
|
```asm
|
|
|
|
MOV R0.l, 0xF
|
|
|
|
MOV R1.l, 0x3
|
|
|
|
ADD
|
|
|
|
MOV [0], R0
|
|
|
|
ZERO R0
|
|
|
|
HALT
|
|
|
|
```
|