This is an old revision of the document!
Buzz Assembly Language Specification
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 logical stack(1) AND stack(2) , pops operands |
or | buzzvm_or(vm) | Pushes the result of logical stack(1) OR stack(2) , pops operands |
not | buzzvm_not(vm) | Pushes the result of logical 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 |
callc | buzzvm_callc(vm) | Calls the closure at stack(1) as a normal closure |
calls | buzzvm_callc(vm) | Calls the closure at stack(1) as a swarm closure |
pushf CONST | buzzvm_pushf(vm, CONST) | Pushes a floating-point constant on the current stack |
pushi CONST | buzzvm_pushi(vm, CONST) | Pushes a 32-bit signed integer constant on the current stack |
pushs SID | buzzvm_pushs(vm, SID) | Pushes a string (identified by the string id SID on the current stack |
pushcn ADDR | buzzvm_pushcn(vm, ADDR) | Pushes the native closure at address ADDR on the current stack |
pushcc CID | buzzvm_pushcc(vm, CID) | Pushes the C closure identified by the id CID on the current stack |
pushl ADDR | buzzvm_pushl(vm, ADDR) | Pushes the lambda at address ADDR on the current stack |
lload IDX | buzzvm_lload(vm, IDX) | Pushes the local variable at index IDX on the current stack; index count starts at 1 . |
lstore IDX | buzzvm_lstore(vm, IDX) | Stores stack(1) into the local variable at index IDX , pops operand; index count starts at 1 |
jump POS | Sets the program counter to POS |
|
jumpz POS | If stack(1) == 0 , sets the program counter to POS ; pops operand |
|
jumpnz POS | If stack(1) != 0 , sets the program counter to POS ; pops operand |