Skip to content

Instantly share code, notes, and snippets.

@AugmentedFifth
Created April 24, 2018 08:53
Show Gist options
  • Save AugmentedFifth/d8c122e302947c9ddc683237653a3699 to your computer and use it in GitHub Desktop.
Save AugmentedFifth/d8c122e302947c9ddc683237653a3699 to your computer and use it in GitHub Desktop.

chapter 8: bytecode format

mnemonic args stack mnemonic explanation semantics
nop - - no operation Does nothing.
push8 byte -> byte push 8-bit Pushes a byte onto the stack.
push32 [byte; 4] -> [byte; 4] push 32-bit Pushes 4 bytes onto the stack.
push64 [byte; 8] -> [byte; 8] push 64-bit Pushes 8 bytes onto the stack.
pushn1i8 - -> -1i8 push negative 1, 8-bit Pushes -1 as a signed byte onto the stack.
push0i8 - -> 0i8 push 0i8 -
push1i8 - -> 1i8 push 1i8 -
push2i8 - -> 2i8 push 2i8 -
push3i8 - -> 3i8 push 3i8 -
push4i8 - -> 4i8 push 4i8 -
push5i8 - -> 5i8 push 5i8 -
pushmaxi8 - -> 127i8 push max value for i8 -
pushn1i32 - -> -1i32 push negative 1, 32-bit -
push0i32 - -> 0i32 push 0i32 -
push1i32 - -> 1i32 push 1i32 -
push2i32 - -> 2i32 push 2i32 -
push3i32 - -> 3i32 push 3i32 -
push4i32 - -> 4i32 push 4i32 -
push5i32 - -> 5i32 push 5i32 -
pushmaxi32 - -> 2147483647i32 push max value for i32 -
pushn1i64 - -> -1i64 push negative 1, 64-bit -
push0i64 - -> 0i64 push 0i64 -
push1i64 - -> 1i64 push 1i64 -
push2i64 - -> 2i64 push 2i64 -
push3i64 - -> 3i64 push 3i64 -
push4i64 - -> 4i64 push 4i64 -
push5i64 - -> 5i64 push 5i64 -
pushmaxi64 - -> 9223372036854775807i64 push max value for i64 -
pushn1f32 - -> -1.0f32 push negative 1, 32-bit floating point -
push0f32 - -> 0.0f32 push 0f32 -
push1f32 - -> 1.0f32 push 1f32 -
push2f32 - -> 2.0f32 push 2f32 -
push3f32 - -> 3.0f32 push 3f32 -
pushinff32 - -> inf32 push infinity, 32-bit floating point -
pushninff32 - -> -inf32 push negative infinity, 32-bit floating point -
pushn1f64 - -> -1.0f64 push negative 1, 64-bit floating point -
push0f64 - -> 0.0f64 push 0f64 -
push1f64 - -> 1.0f64 push 1f64 -
push2f64 - -> 2.0f64 push 2f64 -
push3f64 - -> 3.0f64 push 3f64 -
pushinff64 - -> inf64 push infinity, 64-bit floating point -
pushninff64 - -> -inf64 push negative infinity, 64-bit floating point -
pop u8 [byte; arg1] -> pop off of the stack Pops a number of bytes off of the stack indicated by the first argument.
pop8 - byte -> pop 8 bits off of the stack Pops a single byte from the stack.
pop16 - [byte; 2] -> pop 16 bits off of the stack Pops 2 bytes from the stack.
pop32 - [byte; 4] -> pop 32 bits off of the stack Pops 4 bytes from the stack.
pop64 - [byte; 8] -> pop 64 bits off of the stack Pops 8 bytes from the stack.
pop128 - [byte; 16] -> pop 128 bits off of the stack Pops 16 bytes from the stack.
dup u8 [byte; arg1] -> [byte; arg1 * 2] duplicate Duplicates a number of bytes on top of the stack indicated by the first argument.
dup8 - byte -> byte byte duplicate 8 bits Duplicates a single byte on top of the stack.
dup16 - byte byte -> [byte; 4] duplicate 16 bits Duplicates 2 bytes on top of the stack.
dup32 - [byte; 4] -> [byte; 8] duplicate 32 bits Duplicates 4 bytes on top of the stack.
dup64 - [byte; 8] -> [byte; 16] duplicate 64 bits Duplicates 8 bytes on top of the stack.
dup128 - [byte; 16] -> [byte; 32] duplicate 128 bits Duplicates 16 bytes on top of the stack.
dup256 - [byte; 32] -> [byte; 64] duplicate 256 bits Duplicates 32 bytes on top of the stack.
rot u8, u8 [byte; arg2] [byte; arg1 - arg2] -> [byte; arg1 - arg2] [byte; arg2] rotate Rotates the stack to the left (down), counting arg1 from the top of the stack as the "bottom" and arg2 as the amount to rotate by.
rot8 - byte1 byte2 -> byte2 byte1 rotate 8-bit values Rotates the top 2 8-bit values on the stack.
rot3x8 - byte1 byte2 byte3 -> byte2 byte3 byte1 rotate 3 8-bit values Rotates the top 3 8-bit values on the stack.
rot4x8 - byte1 byte2 byte3 byte4 -> byte2 byte3 byte4 byte1 rotate 4 8-bit values Rotates the top 4 8-bit values on the stack.
rot5x8 - byte1 byte2 byte3 byte4 byte5 -> byte2 byte3 byte4 byte5 byte1 rotate 5 8-bit values Rotates the top 5 8-bit values on the stack.
rot32 - [byte1; 4] [byte2; 4] -> [byte2; 4] [byte1; 4] rotate 32-bit values Rotates the top 2 32-bit values on the stack.
rot3x32 - [byte1; 4] [byte2; 4] [byte3; 4] -> [byte2; 4] [byte3; 4] [byte1; 4] rotate 3 32-bit values Rotates the top 3 32-bit values on the stack.
rot4x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] -> [byte2; 4] [byte3; 4] [byte4; 4] [byte1; 4] rotate 4 32-bit values Rotates the top 4 32-bit values on the stack.
rot5x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] [byte5; 4] -> [byte2; 4] [byte3; 4] [byte4; 4] [byte5; 4] [byte1; 4] rotate 5 32-bit values Rotates the top 5 32-bit values on the stack.
rot64 - [byte1; 8] [byte2; 8] -> [byte2; 8] [byte1; 8] rotate 64-bit values Rotates the top 2 64-bit values on the stack.
rot3x64 - [byte1; 8] [byte2; 8] [byte3; 8] -> [byte2; 8] [byte3; 8] [byte1; 8] rotate 3 64-bit values Rotates the top 3 64-bit values on the stack.
rot4x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] -> [byte2; 8] [byte3; 8] [byte4; 8] [byte1; 8] rotate 4 64-bit values Rotates the top 4 64-bit values on the stack.
rot5x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] [byte5; 8] -> [byte2; 8] [byte3; 8] [byte4; 8] [byte5; 8] [byte1; 8] rotate 5 64-bit values Rotates the top 5 64-bit values on the stack.
rotr u8, u8 [byte; arg1 - arg2] [byte; arg2] -> [byte; arg2] [byte; arg1 - arg2] rotate right Rotates the stack to the left (down), counting arg1 from the top of the stack as the "bottom" and arg2 as the amount to rotate by.
rotr3x8 - byte1 byte2 byte3 -> byte3 byte1 byte2 rotate right 3 8-bit values Rotates the top 3 8-bit values on the stack.
rotr4x8 - byte1 byte2 byte3 byte4 -> byte4 byte1 byte2 byte3 rotate right 4 8-bit values Rotates the top 4 8-bit values on the stack.
rotr5x8 - byte1 byte2 byte3 byte4 byte5 -> byte5 byte1 byte2 byte3 byte4 rotate right 5 8-bit values Rotates the top 5 8-bit values on the stack.
rotr3x32 - [byte1; 4] [byte2; 4] [byte3; 4] -> [byte3; 4] [byte1; 4] [byte2; 4] rotate right 3 32-bit values Rotates the top 3 32-bit values on the stack.
rotr4x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] -> [byte4; 4] [byte1; 4] [byte2; 4] [byte3; 4] rotate right 4 32-bit values Rotates the top 4 32-bit values on the stack.
rotr5x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] [byte5; 4] -> [byte5; 4] [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] rotate right 5 32-bit values Rotates the top 5 32-bit values on the stack.
rotr3x64 - [byte1; 8] [byte2; 8] [byte3; 8] -> [byte3; 8] [byte1; 8] [byte2; 8] rotate right 3 64-bit values Rotates the top 3 64-bit values on the stack.
rotr4x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] -> [byte4; 8] [byte1; 8] [byte2; 8] [byte3; 8] rotate right 4 64-bit values Rotates the top 4 64-bit values on the stack.
rotr5x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] [byte5; 8] -> [byte5; 8] [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] rotate right 5 64-bit values Rotates the top 5 64-bit values on the stack.
over u8, u8 [byte; arg2] [byte; arg1 - arg2] -> [byte; arg2] [byte; arg1 - arg2] [byte; arg2] copy over Copies a value of size arg2 from arg1 below the top of the stack onto the top of the stack.
over8 - byte1 byte2 -> byte1 byte2 byte1 copy over 8-bit value Copies the 2nd 8-bit value from the top of the stack onto the top.
over3x8 - byte1 byte2 byte3 -> byte1 byte2 byte3 byte1 copy over 3rd 8-bit value Copies the 3rd 8-bit value from the top of the stack onto the top.
over4x8 - byte1 byte2 byte3 byte4 -> byte1 byte2 byte3 byte4 byte1 copy over 4th 8-bit value Copies the 4th 8-bit value from the top of the stack onto the top.
over5x8 - byte1 byte2 byte3 byte4 byte5 -> byte1 byte2 byte3 byte4 byte5 byte1 copy over 5th 8-bit value Copies the 5th 8-bit value from the top of the stack onto the top.
over32 - [byte1; 4] [byte2; 4] -> [byte1; 4] [byte2; 4] [byte1; 4] copy over 32-bit value Copies the 2nd 32-bit value from the top of the stack onto the top.
over3x32 - [byte1; 4] [byte2; 4] [byte3; 4] -> [byte1; 4] [byte2; 4] [byte3; 4] [byte1; 4] copy over 3rd 32-bit value Copies the 3rd 32-bit value from the top of the stack onto the top.
over4x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] -> [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] [byte1; 4] copy over 4th 32-bit value Copies the 4th 32-bit value from the top of the stack onto the top.
over5x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] [byte5; 4] -> [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] [byte5; 4] [byte1; 4] copy over 5th 32-bit value Copies the 5th 32-bit value from the top of the stack onto the top.
over64 - [byte1; 8] [byte2; 8] -> [byte1; 8] [byte2; 8] [byte1; 8] copy over 64-bit value Copies the 2nd 64-bit value from the top of the stack onto the top.
over3x64 - [byte1; 8] [byte2; 8] [byte3; 8] -> [byte1; 8] [byte2; 8] [byte3; 8] [byte1; 8] copy over 3rd 64-bit value Copies the 3rd 64-bit value from the top of the stack onto the top.
over4x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] -> [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] [byte1; 8] copy over 4th 64-bit value Copies the 4th 64-bit value from the top of the stack onto the top.
over5x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] [byte5; 8] -> [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] [byte5; 8] [byte1; 8] copy over 5th 64-bit value Copies the 5th 64-bit value from the top of the stack onto the top.
drop u8, u8 [byte; arg2] [byte; arg1 - arg2] -> [byte; arg1 - arg2] drop bottom Drops a value of size arg2 from arg1 below the top of the stack, shifting the part of the stack above it downward.
drop8 - byte1 byte2 -> byte2 drop bottom 8-bit value Drops the 2nd 8-bit value from the top of the stack, shifting the part of the stack above it downward.
drop3x8 - byte1 byte2 byte3 -> byte2 byte3 drop bottom 3rd 8-bit value Drops the 3rd 8-bit value from the top of the stack, shifting the part of the stack above it downward.
drop4x8 - byte1 byte2 byte3 byte4 -> byte2 byte3 byte4 drop bottom 4th 8-bit value Drops the 4th 8-bit value from the top of the stack, shifting the part of the stack above it downward.
drop32 - [byte1; 4] [byte2; 4] -> [byte2; 4] drop bottom 32-bit value Drops the 2nd 32-bit value from the top of the stack, shifting the part of the stack above it downward.
drop3x32 - [byte1; 4] [byte2; 4] [byte3; 4] -> [byte2; 4] [byte3; 4] drop bottom 3rd 32-bit value Drops the 3rd 32-bit value from the top of the stack, shifting the part of the stack above it downward.
drop4x32 - [byte1; 4] [byte2; 4] [byte3; 4] [byte4; 4] -> [byte2; 4] [byte3; 4] [byte4; 4] drop bottom 4th 32-bit value Drops the 4th 32-bit value from the top of the stack, shifting the part of the stack above it downward.
drop64 - [byte1; 8] [byte2; 8] -> [byte2; 8] drop bottom 64-bit value Drops the 2nd 64-bit value from the top of the stack, shifting the part of the stack above it downward.
drop3x64 - [byte1; 8] [byte2; 8] [byte3; 8] -> [byte2; 8] [byte3; 8] drop bottom 3rd 64-bit value Drops the 3rd 64-bit value from the top of the stack, shifting the part of the stack above it downward.
drop4x64 - [byte1; 8] [byte2; 8] [byte3; 8] [byte4; 8] -> [byte2; 8] [byte3; 8] [byte4; 8] drop bottom 4th 64-bit value Drops the 4th 64-bit value from the top of the stack, shifting the part of the stack above it downward.
objnew
objos
objosptr
objwrt
listnew
listix
listixptr
listwrt
ptrdrcpy
ptrdrwrt
free
jmp
cjmp
rjmp
crjmp
call
ccall
rcall
crcall
ret
cret
invoke
cinvoke
eq
jmpeq
jmpeqz
neq
jmpneq
jmpneqz
lt
jmplt
jmpltz
lte
jmplte
jmpltez
gt
jmpgt
jmpgtz
gte
jmpgtez
shl8
shr8
and8
or8
xor8
com8
shl32
shr32
and32
or32
xor32
com32
shl64
shr64
and64
or64
xor64
com64
iadd8
isub8
imul8
idiv8
irem8
ineg8
iadd32
isub32
imul32
idiv32
irem32
ineg32
iadd64
isub64
imul64
idiv64
irem64
ineg64
fadd32
fsub32
fmul32
fdiv32
frem32
fneg32
fadd64
fsub64
fmul64
fdiv64
frem64
fneg64
i8f32
i32f32
i64f32
i8f64
i32f64
i64f64
f32i8
f32i32
f32i64
f64i8
f64i32
f64i64
panic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment