AngelCode Scripting Library byte code instruction set

2004/10/25, Andreas Jönsson

Path control

Instruction Arg Stack inc Suspend
allowed
Exception Description
CALL  int  Takes an integer argument as the function id. Stores stack frame pointer, current function id, and program counter on the call stack. May throw an exception, e.g stack-overflow or system-error from a system function.
CALLSYS  int  Takes an integer argument as the function id. Stores stack frame pointer, current function id, and program counter on the call stack. May throw an exception, e.g stack-overflow or system-error from a system function.
CALLBND  int  Takes an integer argument as the function id. Stores stack frame pointer, current function id, and program counter on the call stack. May throw an exception, e.g stack-overflow or system-error from a system function.
RET  word  -arg Restores stack frame pointer, current function id, and program counter from the call stack. Pops the stack.
JMP  int  Add the integer argument to the program counter.
JZ  int  -1  Pops the stack, and if the value is 0, adds the integer argument to the program counter.
JNZ  int  -1  Pops the stack, and if the value is not 0, adds the integer argument to the program counter.
JS  int  -1  Pops the stack, and if the value is negative, adds the integer argument to the program counter.
JNS  int  -1  Pops the stack, and if the value is not negative, adds the integer argument to the program counter.
JP  int  -1  Pops the stack, and if the value is positive (> 0), adds the integer argument to the program counter.
JNP  int  -1  Pops the stack, and if the value is not positive, adds the integer argument to the program counter.
JMPP  -1  Pops the offset from the stack and then jumps.
TZ  Pops the stack, and if the value is 0, pushes 1 on the stack, otherwise pushes 0.
TNZ  Pops the stack, and if the value is not 0, pushes 1 on the stack, otherwise pushes 0.
TS  Pops the stack, and if the value is signed (i.e. negative), pushes 1 on the stack, otherwise pushes 0.
TNS  Pops the stack, and if the value is not signed (i.e. not negative), pushes 1 on the stack, otherwise pushes 0.
TP  Pops the stack, and if the value is larger than 0, pushes 1 on the stack, otherwise pushes 0.
TNP  Pops the stack, and if the value is not larger than 0, pushes 1 on the stack, otherwise pushes 0.
PEID  +1  Pushes the exception location id on the stack.
SUSPEND  Checks an internal flag to see if the execution should be suspended.
END  Ends the exception handler for a particular function.

Memory access

Instruction Arg Stack inc Exception Description
POP  word  -arg  Descreases the stack pointer with the number of dwords specified.
PUSH  word  +arg  Increases the stack pointer with the number of dwords specified.
SET4  dword  +1  Pushes a dword on the stack with the value in the argument.
SET8  qword  +2  Pushes a qword on the stack with the value in the argument.
RD4  Pops the address to read from, and then pushes the dword from the address on the stack.
RD8  +1  Pops the address to read from, and then pushes the qword from the address on the stack.
WRT1  -1  Pops the address to write to, then writes the lower byte of the top dword to that address.
WRT2  -1  Pops the address to write to, then writes the lower word of the top dword to that address.
WRT4  -1  Pops the address to write to, then writes the top dword on the stack to that address.
WRT8  -1  Pops the address to write to, then writes the top qword on the stack to that address.
COPY  word  -1  Pops the target address, reads the source address, then copies the bytes. May throw null-pointer-access.
PSF  short  +1  Pushes the stack frame pointer added with the argument on the stack.
PGA  int  +1  Pushes a pointer to the global address space offset with the parameter on the stack.
SWAP4  Swaps the top two dwords.
SWAP8  Swaps the top two qwords.
STORE4  Stores the top dword in a temporary register.
RECALL4  Pushes the dword in the temporary register on the stack.
ADDOFF  -1  Pops the byte offset, pops a variable reference. Adds the offset to the value that the variable points to and pushes the result on the stack. Throws null-pointer-access if the variable holds a null pointer.
MOV4  -2  Same as WRT4 followed by a POP 1.
RDSF4  short  +1  The same as PSF followed by RD4.
MOVSF4  short  -1  The same as PSF followed by MOV4.
RDGA4  int  +1  The same as PGA followed by RD4.
MOVGA4  int  -1  The same as PGA followed by MOV4.
PUSHZERO  +1  Does the same thing as SET4 0.
SRET4  -1  Pops (stores) the top DWORD into the return register.
SRET8  -2  Pops (stores) the top QWORD into the return register.
RRET4  +1  Pushes (recalls) a DWORD from the return register on the stack.
RRET8  +2  Pushes (recalls) a QWORD from the return register on the stack.
STR  word  +2  Pushes the address of the string on the stack, then the size of the string.

Integer operations

Instruction Arg Stack inc Exception Description
ADDi  -1  Pops the top two integers, adds them, then pushes the result on the stack.
SUBi  -1  Pops the top two integers, subtracts them, then pushes the result on the stack.
ADDIi  int  Optimizes SET4, ADDi.
SUBIi  int  Optimizes SET4, SUBi.
MULi  -1  Pops the top two integers, multiplies them, then pushes the result on the stack.
DIVi  -1  Pops the divider, pops the dividend, divides the dividend with the divider, then pushes the result on the stack. May throw a divide-by-zero exception.
MODi  -1  Pops the divider, pops the dividend, integer divides the dividend with the divider, then pushes the remaining part on the stack. May throw a divide-by-zero exception.
NEGi  Negates the top integer value on the stack.
CMPi  -1  Pops b, pops a, computes a-b. If result == 0 pushes 0, else if result < 0 pushes -1, else pushes 1.
CMPui  -1  Same as CMPi, except that it treats the values as unsigned integers.
CMPIi  int  Pops a, computes a-arg. If result == 0 pushes 0, else if result < 0 pushes -1, else pushes 1.
CMPIui  uint  Same as CMPi, except that it treats the values as unsigned integers.
INCi  Reads the top address, without popping it, and increases its value.
INCi8  The same as INCi, except that it treats the value pointed to by the address as an 8 bit value.
INCi16  The same as INCi, except that it treats the value pointed to by the address as an 16 bit value.
DECi  Reads the top address, without popping it, and decreases its value.
DECi8  The same as DECi, except that it treats the value pointed to by the address as an 8 bit value.
DECi16  The same as DECi, except that it treats the value pointed to by the address as an 16 bit value.

Floating point operations

Instruction Arg Stack inc Exception Description
ADDf  -1  Pops the top two floats, adds them, then pushes the result on the stack.
SUBf  -1  Pops the top two floats, subtracts them, then pushes the result on the stack.
ADDIf  float  Optimizes SET4, ADDf.
SUBIf  float  Optimizes SET4, SUBf.
MULf  -1  Pops the top two floats, multiplies them, then pushes the result on the stack.
DIVf  -1  Pops the divider, pops the dividend, divides the dividend with the divider, then pushes the result on the stack. May throw a divide-by-zero exception.
MODf  -1  Pops the divider, pops the dividend, integer divides the dividend with the divider, then pushes the remaining part on the stack. May throw a divide-by-zero exception.
NEGf  Negates the top float value on the stack.
CMPf  -1  Pops b, pops a, computes a-b. If result == 0 pushes 0, else if result < 0 pushes -1, else pushes 1.
CMPIf  float  Optimizes SET4, CMPf.
INCf  Reads the top address, without popping it, and increases its value.
DECf  Reads the top address, without popping it, and decreases its value.

Double operations

Instruction Arg Stack inc Exception Description
ADDd  -2  Pops the top two doubles, adds them, then pushes the result on the stack.
SUBd  -2  Pops the top two doubles, subtracts them, then pushes the result on the stack.
MULd  -2  Pops the top two doubles, multiplies them, then pushes the result on the stack.
DIVd  -2  Pops the divider, pops the dividend, divides the dividend with the divider, then pushes the result on the stack. May throw a divide-by-zero exception.
MODd  -2  Pops the divider, pops the dividend, integer divides the dividend with the divider, then pushes the remaining part on the stack. May throw a divide-by-zero exception.
NEGd  Negates the top double value on the stack.
CMPd  -3  Pops b, pops a, computes a-b. If result == 0 pushes 0, else if result < 0 pushes -1, else pushes 1.
INCd  Reads the top address, without popping it, and increases its value.
DECd  Reads the top address, without popping it, and decreases its value.

Bitwise operations

Instruction Arg Stack inc Exception Description
BNOT  Inverts all bits in the top dword on the stack.
BAND  -1  Pops two dwords from the stack, computes the bitwise and, then pushes the result on the stack.
BOR  -1  Pops two dwords from the stack, computes the bitwise or, then pushes the result on the stack.
BXOR  -1  Pops two dwords from the stack, computes the bitwise xor, then pushes the result on the stack.
BSLL  -1  Pops an integer, pops a dword, computes the logical left shift, then pushes the result on the stack.
BSRL  -1  Pops an integer, pops a dword, computes the logical right shift, then pushes the result on the stack.
BSRA  -1  Pops an integer, pops a dword, computes the arithmetic right shift, then pushes the result on the stack.

Type conversion

Instruction Arg Stack inc Exception Description
I2F  Converts the top integer to a float.
F2I  Converts the top float to an integer.
UI2F  Converts the top unsigned integer to a float.
F2UI  Converts the top float to an unsigned integer.
SB  Converts the top dword to a signed 8 bit integer, this is done by extending the 8th bit to the top 24 bits.
SW  Converts the top dword to a signed 16 bit integer, this is done by extending the 16th bit to the top 16 bits.
UB  Converts the top dword to an unsigned 8 bit integer, this is done by setting the top 24 bits to zero.
UW  Converts the top dword to an unsigned 16 bit integer, this is done by setting the top 16 bits to zero.
dTOi  -1  Converts the top double to an integer.
dTOui  -1  Converts the top double to an unsigned integer.
dTOf  -1  Converts the top double to a float.
iTOd  +1  Converts the top integer to a double.
uiTOd  +1  Converts the top unsigned integer to a double.
fTOd  +1  Converts the top float to a double.

top