will be final label and must end with start
can be embedded in switch table or at location of main
location of jump table
stack register pointer. Contains the frame reference for functions.
Top Of Stack index
Logically the value at top of stack.
There is no literal value TOP but it is useful for this reference.
push(TOS) load(0) would duplicate TOP
push a number onto the stack
val may be a integer literal, or SP
Stack grows.
logicaly STACK[++TOS]=val
loads the stack with a value fetched from BASE+TOP
BASE should be 0 or SP.
Top should contain offset.
TOP is replaced with value at STACK[BASE+TOP].
stores the value at top fetched from base+offset
offset being currently on the stack
BASE can be 0 or SP.
2 values popped from the stack.
branches to location LABEL if TOP == zero.
TOP is popped.
branches to location LABEL if TOP != zero.
TOP is popped.
unconditional branch to location LABEL
stack is ignored.
all operators reduce the stack size by one.
The new top is replaced by the result of the operation.
TOP = left OP Right
where left and right are values on the stack (right is TOP)
Relational Operations
eq ==
lt <
gt >
ne !=
nlt >=
ngt <=
Integer Operations
div /
mult *
sub -
add +
calls a function whose id is at TOP
ARGC is the number of parameters being passed to the function.
A function returns a value which is at top
A function returns without a value
This is how functions ids are associated with labels.
2 functions are automatic, input and output.
0 must go to init.
The last fuunction should be main and labeled as such.
After the call switch the INIT label provides a location to initialize global variables.
The INIT region should end with the keyword start (which among other things will jump to MAIN).
INIT must be the last region and start must be the end of the file.
CALLSWITCH: jumptable entry( -2 , INPUT ) entry ( -1 , OUTPUT ) entry ( 0 , INIT ) entry ( 1 , LABEL_F1 ) MAIN: entry ( 2 , LABEL_F2 ) endtable INIT: start
but this would be ok as well (Assuming main was labeled MAIN)
CALLSWITCH: jumptable entry( -2 , INPUT ) entry ( -1 , OUTPUT ) entry ( 0 , INIT ) entry ( 1 , LABEL_F1 ) entry ( 2 , MAIN ) endtable INIT: start