buzz_assembler

This is an old revision of the document!


The Buzz Virtual Machine (BVM) is a stack machine that works with a custom assembly language. The instruction set is composed of 46 elements. Each command can be used either by writing Buzz Assembly code directly (in a .basm file), or through C-functions.

The table below reports both the plain assembly command and the corresponding C function, along with a brief description of the effect of a command. In the description, stack(N) stands for the N-th element on the stack. The stack-top element is stack(1); the element beneath it is stack(2), and so on. If the stack contains K elements, the bottom element is stack(K).

Command C function Description
nop No operation
done buzzvm_done(vm) Ends the execution
pushnil buzzvm_pushnil(vm) Pushes nil on the current stack
dup buzzvm_dup(vm) Pushes stack(1) on the current stack
pop buzzvm_pop(vm) Removes stack(1) from the current stack
ret0 buzzvm_ret0(vm) Returns from a closure call without returning a value to the caller
ret1 buzzvm_ret0(vm) Returns from a closure call and returns the current stack(1) to the caller
add buzzvm_add(vm) Pushes the result of stack(1)+stack(2), pops operands
sub buzzvm_sub(vm) Pushes the result of stack(1)-stack(2), pops operands
mul buzzvm_mul(vm) Pushes the result of stack(1)*stack(2), pops operands
div buzzvm_div(vm) Pushes the result of stack(1)/stack(2), pops operands
mod buzzvm_mod(vm) Pushes the result of stack(1)%stack(2), pops operands
pow buzzvm_pow(vm) Pushes the result of stack(1)^stack(2), pops operands
unm buzzvm_unm(vm) Pushes -stack(1), pops operand
and buzzvm_and(vm) Pushes the result of stack(1) AND stack(2), pops operands
or buzzvm_or(vm) Pushes the result of stack(1) OR stack(2), pops operands
not buzzvm_not(vm) Pushes NOT stack(1), pops operand
eq buzzvm_eq(vm) Pushes the result of stack(1) == stack(2), pops operands
neq buzzvm_neq(vm) Pushes the result of stack(1) != stack(2), pops operands
gt buzzvm_gt(vm) Pushes the result of stack(1) > stack(2), pops operands
gte buzzvm_gte(vm) Pushes the result of stack(1) >= stack(2), pops operands
lt buzzvm_lt(vm) Pushes the result of stack(1) < stack(2), pops operands
lte buzzvm_lte(vm) Pushes the result of stack(1) ⇐ stack(2), pops operands
gload buzzvm_gload(vm) Pushes the global variable corresponding to string at stack(1), pops operand
gstore buzzvm_gstore(vm) Stores stack(1) into global variable whose name is at stack(2), pop operands
pusht buzzvm_pusht(vm) Pushes an empty table on the current stack
tput buzzvm_tput(vm) Performs t[k] = v; v is stack(1), k is stack(2)), t is stack(3); pops operands
tget buzzvm_tget(vm) Pushes t[k] on the current stack; k is stack(1)), t is stack(2); pops operands
  • buzz_assembler.1460138650.txt.gz
  • Last modified: 2016/04/08 18:04
  • by root