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.4 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
	instructions

instructions
	instruction
	instruction '\n' instructions

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'
	'PRTRD'
	'RDPRT'
	'WRPRT'

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

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