AngelScript

Byte code instructions

This page gives a brief description of each of the byte code instructions that the virtual machine has.

- Object management
- Math instructions
- Bitwise instructions
- Comparisons
- Type conversions
- Increment and decrement
- Flow control
- Stack and data management
- Global variables

## Object management

Perform a bitwise copy of a memory buffer to another

- asBC_COPY

Push the address and length of a string on the stack

- asBC_STR

Allocate the memory for an object and setup the VM to execute the constructor

- asBC_ALLOC

Release the memory of an object

- asBC_FREE

Move the address in an object variable to the object register. The address in the variable is then cleared.

- asBC_LOADOBJ

Move the address from the object register to an object variable. The address in the object register is then cleared.

- asBC_STOREOBJ

Copy the object handle from one address to another. The reference count of the object is updated to reflect the copy.

- asBC_REFCPY

Push the pointer of an object type on the stack

- asBC_OBJTYPE

Push the type id on the stack

- asBC_TYPEID

Pop an address to a script object from the stack. If the desired cast can be made store the address in the object register.

- asBC_Cast

Push the function pointer on the stack

- asBC_FuncPtr

Load the address to a property of the object into the value register. Substitutes the sequence PshV4/8, ADDSi, PopRPtr.

- asBC_LoadThisR
- asBC_LoadRObjR

Load the address to a property of a value object into the value register. Substitutes the sequence PSF, ADDSi, PopRPtr.

- asBC_LoadVObjR

## Math instructions

Negate the value in the variable. The original value is overwritten.

- asBC_NEGi
- asBC_NEGf
- asBC_NEGd
- asBC_NEGi64

Perform the operation with the value of two variables and store the result in a third variable.

- asBC_ADDi
- asBC_SUBi
- asBC_MULi
- asBC_DIVi
- asBC_MODi

- asBC_ADDf
- asBC_SUBf
- asBC_MULf
- asBC_DIVf
- asBC_MODf

- asBC_ADDd
- asBC_SUBd
- asBC_MULd
- asBC_DIVd
- asBC_MODd

- asBC_ADDi64
- asBC_SUBi64
- asBC_MULi64
- asBC_DIVi64
- asBC_MODi64

Perform the operation with a constant value and the value of the variable. The original value is overwritten.

- asBC_ADDIi
- asBC_SUBIi
- asBC_MULIi

- asBC_ADDIf
- asBC_SUBIf
- asBC_MULIf

## Bitwise instructions

Perform a boolean not operation on the value in the variable. The original value is overwritten.

- asBC_NOT

Perform a bitwise complement on the value in the variable. The original value is overwritten.

- asBC_BNOT
- asBC_BNOT64

Perform the operation with the value of two variables and store the result in a third variable.

- asBC_BAND
- asBC_BOR
- asBC_BXOR

- asBC_BAND64
- asBC_BOR64
- asBC_BXOR64

- asBC_BSLL
- asBC_BSRL
- asBC_BSRA

- asBC_BSLL64
- asBC_BSRL64
- asBC_BSRA64

## Comparisons

Compare the value of two variables and store the result in the value register.

- asBC_CMPi
- asBC_CMPu
- asBC_CMPf
- asBC_CMPd
- asBC_CMPi64
- asBC_CMPu64

Compare the value of a variable with a constant and store the result in the value register.

- asBC_CMPIi
- asBC_CMPIu
- asBC_CMPIf

Test the value in the value register. Update the value register according to the result.

- asBC_TZ
- asBC_TNZ
- asBC_TS
- asBC_TNS
- asBC_TP
- asBC_TNP

## Type conversions

Convert the value in the variable. The original value is overwritten.

- asBC_iTOb
- asBC_iTOw
- asBC_sbTOi
- asBC_swTOi
- asBC_ubTOi
- asBC_uwTOi

- asBC_iTOf
- asBC_fTOi
- asBC_uTOf
- asBC_fTOu

- asBC_dTOi64
- asBC_dTOu64
- asBC_i64TOd
- asBC_u64TOd

Convert the value of a variable and store the result in another variable.

- asBC_dTOi
- asBC_dTOu
- asBC_dTOf
- asBC_iTOd
- asBC_uTOd
- asBC_fTOd

- asBC_i64TOi
- asBC_i64TOf
- asBC_u64TOf
- asBC_uTOi64
- asBC_iTOi64
- asBC_fTOi64
- asBC_fTOu64

## Increment and decrement

Increment or decrement the value pointed to by the address in the value register.

- asBC_INCi8
- asBC_DECi8
- asBC_INCi16
- asBC_DECi16
- asBC_INCi
- asBC_DECi
- asBC_INCi64
- asBC_DECi64
- asBC_INCf
- asBC_DECf
- asBC_INCd
- asBC_DECd

Increment or decrement the value in the variable.

- asBC_IncVi
- asBC_DecVi

## Flow control

Setup the VM to begin execution of the other script function

- asBC_CALL
- asBC_CALLINTF
- asBC_CALLBND
- asBC_CallPtr

Setup the VM to return to the calling function

- asBC_RET

Make an unconditional jump to a relative position

- asBC_JMP

Make a jump to a relative position depending on the value in the value register

- asBC_JZ
- asBC_JNZ
- asBC_JS
- asBC_JNS
- asBC_JP
- asBC_JNP
- asBC_JMPP

Call an application registered function

- asBC_CALLSYS

Save the state and suspend execution, then return control to the application

- asBC_SUSPEND

Give control of execution to the JIT compiled function

- asBC_JitEntry

## Stack and data management

Update the stack pointer.

- asBC_POP
- asBC_PUSH

Push a constant value on the stack.

- asBC_PshC4
- asBC_PshC8

Push the stack frame pointer on the stack.

- asBC_PSF

Swap the top values on the stack.

- asBC_SWAP4
- asBC_SWAP8
- asBC_SWAP48
- asBC_SWAP84

Pop an address from the stack, read a value from the address and push it on the stack.

- asBC_RDS4
- asBC_RDS8

Add an offset to the top address on the stack.

- asBC_ADDSi

Push the value of a variable on the stack.

- asBC_PshV4
- asBC_PshV8

Initialize the value of a variable with a constant.

- asBC_SetV1
- asBC_SetV2
- asBC_SetV4
- asBC_SetV8

Copy the value of one variable to another.

- asBC_CpyVtoV4
- asBC_CpyVtoV8

Validate that an expected pointer is not null.

- asBC_CHKREF
- asBC_ChkRefS
- asBC_ChkNullV
- asBC_ChkNullS

Push the variable index with the size of a pointer on the stack.

- asBC_VAR

Replace a variable index on the stack with an address.

- asBC_GETREF
- asBC_GETOBJ
- asBC_GETOBJREF

Pop or push an address to or from the value register.

- asBC_PopRPtr
- asBC_PshRPtr

Copy a value between value register and a variable.

- asBC_CpyVtoR4
- asBC_CpyVtoR8
- asBC_CpyRtoV4
- asBC_CpyRtoV8

Copy a value from a variable to the address held in the value register

- asBC_WRTV1
- asBC_WRTV2
- asBC_WRTV4
- asBC_WRTV8

Copy a value from the address held in the value register to a variable

- asBC_RDR1
- asBC_RDR2
- asBC_RDR4
- asBC_RDR8

Load the address of the variable into the value register

- asBC_LDV

Clear the upper bytes of the value register

- asBC_ClrHi

## Global variables

Push the value of a global variable on the stack

- asBC_PshG4

Load the address of a global variable into the value register

- asBC_LDG

Load the address of a global variable into the value register and copy the value of the global variable to local variable

- asBC_LdGRdR4

Copy a value between local variable and global variable.

- asBC_CpyVtoG4
- asBC_CpyGtoV4

Push the address of the global variable on the stack.

- asBC_PGA

Initialize the variable of a global variable with a constant.

- asBC_SetG4