stacard vm reference

Opcode Assembler syntax Description
000 brk Stop machine
1xx ld (@label or address) Load value from address, push to stack
2xx st (@label or address) Pop value from stack, store at address
4xx jsr (@label or address) Push program counter to stack, jump to address
5xx jmp (@label or address) Jump to address
6xx jz (@label or address) Jump to address if stack top is zero
7xx jlz (@label or address) Jump to address if stack top is negative
8xx io (device):(device port) Send stack top to device
800 out Print stack top as number
801 printch Print stack top as ASCII character
301 dup Copy stack top
302 drop Remove stack top
303 swap Swap two top stack values
304 ovr Push to stack value before top
310 rnd Push random number to stack
311 add Pop 2 numbers, add, push result to stack
312 sub Pop 2 numbers, subtract, push result to stack
313 and Pop 2 numbers, apply logical AND, push result to stack
314 or Pop 2 numbers, apply logical OR, push result to stack
315 xor Pop 2 numbers, apply logical XOR, push result to stack
316 rsh Pop 2 numbers, apply right bitshift, push result to stack
317 lsh Pop 2 numbers, apply left bitshift, push result to stack
318 inc Add 1 to stack top
319 dec Subtract 1 from stack top
321 neg Change stack top sign
322 inv Invert stack top bits
330 ji Pop address from stack, jump to address

Example program

	ld @strptr        ; load string address
	{
		dup
		jsr @iload    ; call subroutine for indirect load
		jz =end       ; if zero jump outside of brackets block (=end)
		printch
		drop
		inc
		jmp =begin    ; jump to block start
	}
	drop              ; clean stack
	drop
	brk
str:
	string Hello
	data 32
	string world!
	data 0
strptr:
	data @str
load_op:
	data 100
iload:
	swap
	ld @load_op
	add               ; making ld instruction with passed address
	st @iload2        ; indirect loading via self-modifying code
iload2:
	brk
	swap
	ji