4-bit virtual CPU
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1.5 KiB

ASM SYNTAX

Grammar is described via McKeeman Form.

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' register
	'DEC' register
	'ADD'
	'SUB'
	'AND'
	'OR'
	'XOR'
	'XNOR'
	'COMPL' register
	'SETC' carry
	'NOP'
	'HALT'
	'CLOAD' register
	'ZERO' register
	'DIV'
	'MUL'
	'SWAP'
	'PRTCHK'
	'PRTRD'
	'PRTWR'
	'LOAD'
	'STORE'

carry
    '0'
    '1'

mov
	'MOV' register-half ',' digit(0, 15)
	'MOV' register ',' register

jmp
	'JMP' digit(-16, -1)
	'JMP' digit(1, 16)
	'JMPC' digit(-16, -1)
	'JMPC' digit(1, 16)
	'AJMP' register
	'AJMPC' register

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'

register-half
	register '.l'
	register '.h'

Comments are introduced with #, like in Bash.

Missing stuff

There are no labels. We will probably implement them in future. Or we will probably not.

Sample program

MOV R0.l, 0xF
MOV R1.l, 0x3
ADD
MOV [0], R0
ZERO R0
HALT