Alan Opcode Reference

The Alan Standard Library, AMM, and AGA formats all make extensive use of opcodes defined within the Alan VM to do useful work.

The AVM opcodes are identified with a 64-bit integer and have exactly 3 64-bit arguments. The 64-bit integers have been chosen to match a space-padded string of the name of the opcode (therefore allowing the opcodes to have names from 1-8 ASCII characters long). Most opcodes use the first two arguments as input addresses and the last argument as an output address, but some treat them as constants, event ids, or ignored values.

The following table will specify the opcode name followed by the three arguments (arg0, arg1, arg2) with the kind of argument given (IN = Input Address, OUT = Output Address, CONST = Constant Value, EVENT = Event Name, NULL = Ignored) and then a short description of what that opcode does. A few opcodes will have an UNSAFE flag on them in their description. These opcodes can potentially crash the AVM if called incorrectly and rely on the compiler to use them wisely.

Opcodearg0arg1arg2Description
i8f64INNULLOUTConverts an i8 to an f64
i16f64INNULLOUTConverts an i16 to an f64
i32f64INNULLOUTConverts an i32 to an f64
i64f64INNULLOUTConverts an i64 to an f64
f32f64INNULLOUTConverts an f32 to an f64
strf64INNULLOUTConverts a string to an f64
boolf64INNULLOUTConverts a bool to an f64
i8f32INNULLOUTConverts an i8 to an f32
i16f32INNULLOUTConverts an i16 to an f32
i32f32INNULLOUTConverts an i32 to an f32
i64f32INNULLOUTConverts an i64 to an f32
f64f32INNULLOUTConverts an f64 to an f32
strf32INNULLOUTConverts a string to an f32
boolf32INNULLOUTConverts a bool to an f32
i8i64INNULLOUTConverts an i8 to an i64
i16i64INNULLOUTConverts an i16 to an i64
i32i64INNULLOUTConverts an i32 to an i64
f32i64INNULLOUTConverts an f32 to an i64
f64i64INNULLOUTConverts an f64 to an i64
stri64INNULLOUTConverts a string to an i64
booli64INNULLOUTConverts a bool to an i64
i8i32INNULLOUTConverts an i8 to an i32
i16i32INNULLOUTConverts an i16 to an i32
i64i32INNULLOUTConverts an i64 to an i32
f32i32INNULLOUTConverts an f32 to an i32
f64i32INNULLOUTConverts an f64 to an i32
stri32INNULLOUTConverts a string to an i32
booli32INNULLOUTConverts a bool to an i32
i8i16INNULLOUTConverts an i8 to an i16
i32i16INNULLOUTConverts an i32 to an i16
i64i16INNULLOUTConverts an i64 to an i16
f32i16INNULLOUTConverts an f32 to an i16
f64i16INNULLOUTConverts an f64 to an i16
stri16INNULLOUTConverts a string to an i16
booli16INNULLOUTConverts a bool to an i16
i16i8INNULLOUTConverts an i16 to an i8
i32i8INNULLOUTConverts an i32 to an i8
i64i8INNULLOUTConverts an i64 to an i8
f32i8INNULLOUTConverts an f32 to an i8
f64i8INNULLOUTConverts an f64 to an i8
stri8INNULLOUTConverts a string to an i8
booli8INNULLOUTConverts a bool to an i8
i8boolINNULLOUTConverts an i8 to a bool
i16boolINNULLOUTConverts an i16 to a bool
i32boolINNULLOUTConverts an i32 to a bool
i64boolINNULLOUTConverts an i64 to a bool
f32boolINNULLOUTConverts an f32 to a bool
f64boolINNULLOUTConverts an f64 to a bool
strboolINNULLOUTConverts a string to a bool
i8strINNULLOUTConverts an i8 to a string
i16strINNULLOUTConverts an i16 to a string
i32strINNULLOUTConverts an i32 to a string
i64strINNULLOUTConverts an i64 to a string
f32strINNULLOUTConverts an f32 to a string
f64strINNULLOUTConverts an f64 to a string
boolstrINNULLOUTConverts a bool to a string
addi8ININOUTAdds two i8's together
addi16ININOUTAdds two i16's together
addi32ININOUTAdds two i32's together
addi64ININOUTAdds two i64's together
addf32ININOUTAdds two f32's together
addf64ININOUTAdds two f64's together
subi8ININOUTSubtracts the second i8 from the first
subi16ININOUTSubtracts the second i16 from the first
subi32ININOUTSubtracts the second i32 from the first
subi64ININOUTSubtracts the second i64 from the first
subf32ININOUTSubtracts the second f32 from the first
subf64ININOUTSubtracts the second f64 from the first
negi8INNULLOUTNegates the i8
negi16INNULLOUTNegates the i16
negi32INNULLOUTNegates the i32
negi64INNULLOUTNegates the i64
negf32INNULLOUTNegates the f32
negf64INNULLOUTNegates the f64
absi8INNULLOUTMakes the i8 magnitude positive
absi16INNULLOUTMakes the i16 magnitude positive
absi32INNULLOUTMakes the i32 magnitude positive
absi64INNULLOUTMakes the i64 magnitude positive
absf32INNULLOUTMakes the f32 magnitude positive
absf64INNULLOUTMakes the f64 magnitude positive
muli8ININOUTMultiplies the two i8's together
muli16ININOUTMultiplies the two i16's together
muli32ININOUTMultiplies the two i32's together
muli64ININOUTMultiplies the two i64's together
mulf32ININOUTMultiplies the two f32's together
mulf64ININOUTMultiplies the two f64's together
divi8ININOUTDivides the first i8 by the second
divi16ININOUTDivides the first i16 by the second
divi32ININOUTDivides the first i32 by the second
divi64ININOUTDivides the first i64 by the second
divf32ININOUTDivides the first f32 by the second
divf64ININOUTDivides the first f64 by the second
modi8ININOUTDivides the first i8 by the second and returns the remainder
modi16ININOUTDivides the first i16 by the second and returns the remainder
modi32ININOUTDivides the first i32 by the second and returns the remainder
modi64ININOUTDivides the first i64 by the second and returns the remainder
powi8ININOUTRaises the first i8 by the second's power
powi16ININOUTRaises the first i16 by the second's power
powi32ININOUTRaises the first i32 by the second's power
powi64ININOUTRaises the first i64 by the second's power
powf32ININOUTRaises the first f32 by the second's power
powf64ININOUTRaises the first f64 by the second's power
sqrtf32INNULLOUTReturns the square root of the f32
sqrtf64INNULLOUTReturns the square root of the f64
andi8ININOUTReturns the bitwise and of the two i8's
andi16ININOUTReturns the bitwise and of the two i16's
andi32ININOUTReturns the bitwise and of the two i32's
andi64ININOUTReturns the bitwise and of the two i64's
andboolININOUTReturns the boolean and of the two bool's
ori8ININOUTReturns the bitwise or of the two i8's
ori16ININOUTReturns the bitwise or of the two i16's
ori32ININOUTReturns the bitwise or of the two i32's
ori64ININOUTReturns the bitwise or of the two i64's
orboolININOUTReturns the boolean or of the two bool's
xori8ININOUTReturns the bitwise xor of the two i8's
xori16ININOUTReturns the bitwise xor of the two i16's
xori32ININOUTReturns the bitwise xor of the two i32's
xori64ININOUTReturns the bitwise xor of the two i64's
xorboolININOUTReturns the boolean xor of the two bool's
noti8INNULLOUTReturns the bitwise not of the i8
noti16INNULLOUTReturns the bitwise not of the i16
noti32INNULLOUTReturns the bitwise not of the i32
noti64INNULLOUTReturns the bitwise not of the i64
notboolINNULLOUTReturns the boolean not of the bool
nandi8ININOUTReturns the bitwise nand of the two i8's
nandi16ININOUTReturns the bitwise nand of the two i16's
nandi32ININOUTReturns the bitwise nand of the two i32's
nandi64ININOUTReturns the bitwise nand of the two i64's
nandbooININOUTReturns the boolean nand of the two bool's
nori8ININOUTReturns the bitwise nor of the two i8's
nori16ININOUTReturns the bitwise nor of the two i16's
nori32ININOUTReturns the bitwise nor of the two i32's
nori64ININOUTReturns the bitwise nor of the two i64's
norboolININOUTReturns the boolean nor of the two bool's
xnori8ININOUTReturns the bitwise xnor of the two i8's
xnori16ININOUTReturns the bitwise xnor of the two i16's
xnori32ININOUTReturns the bitwise xnor of the two i32's
xnori64ININOUTReturns the bitwise xnor of the two i64's
xnorbooININOUTReturns the boolean xnor of the two bool's
eqi8ININOUTDetermines if the two i8's are equal
eqi16ININOUTDetermines if the two i16's are equal
eqi32ININOUTDetermines if the two i32's are equal
eqi64ININOUTDetermines if the two i64's are equal
eqf32ININOUTDetermines if the two f32's are equal
eqf64ININOUTDetermines if the two f64's are equal
eqstrININOUTDetermines if the two str's are equal
eqboolININOUTDetermines if the two bool's are equal
neqi8ININOUTDetermines if the two i8's are not equal
neqi16ININOUTDetermines if the two i16's are not equal
neqi32ININOUTDetermines if the two i32's are not equal
neqi64ININOUTDetermines if the two i64's are not equal
neqf32ININOUTDetermines if the two f32's are not equal
neqf64ININOUTDetermines if the two f64's are not equal
neqstrININOUTDetermines if the two str's are not equal
neqboolININOUTDetermines if the two bool's are not equal
lti8ININOUTDetermines if the first i8 is less than the second
lti16ININOUTDetermines if the first i16 is less than the second
lti32ININOUTDetermines if the first i32 is less than the second
lti64ININOUTDetermines if the first i64 is less than the second
ltf32ININOUTDetermines if the first f32 is less than the second
ltf64ININOUTDetermines if the first f64 is less than the second
ltstrININOUTDetermines if the first str is less than the second
ltei8ININOUTDetermines if the first i8 is less than or equal to the second
ltei16ININOUTDetermines if the first i16 is less than or equal to the second
ltei32ININOUTDetermines if the first i32 is less than or equal to the second
ltei64ININOUTDetermines if the first i64 is less than or equal to the second
ltef32ININOUTDetermines if the first f32 is less than or equal to the second
ltef64ININOUTDetermines if the first f64 is less than or equal to the second
ltestrININOUTDetermines if the first str is less than or equal to the second
gti8ININOUTDetermines if the first i8 is greater than the second
gti16ININOUTDetermines if the first i16 is greater than the second
gti32ININOUTDetermines if the first i32 is greater than the second
gti64ININOUTDetermines if the first i64 is greater than the second
gtf32ININOUTDetermines if the first f32 is greater than the second
gtf64ININOUTDetermines if the first f64 is greater than the second
gtstrININOUTDetermines if the first str is greater than the second
gtei8ININOUTDetermines if the first i8 is greater than or equal to the second
gtei16ININOUTDetermines if the first i16 is greater than or equal to the second
gtei32ININOUTDetermines if the first i32 is greater than or equal to the second
gtei64ININOUTDetermines if the first i64 is greater than or equal to the second
gtef32ININOUTDetermines if the first f32 is greater than or equal to the second
gtef64ININOUTDetermines if the first f64 is greater than or equal to the second
gtestrININOUTDetermines if the first str is greater than or equal to the second
catstrININOUTConcatenates the first string to the second (non-mutating result in output)
splitININOUTSplits the first string by all occurrences of the second into a new array of strings
repstrININOUTRepeats the string (first arg) by the specified number of occurrences (second arg) in a new string (output arg)
matchesININOUTDetermines if the second arg string, treated as a regular expression, matches the first string
indstrININOUTDetermines the index of the second string occurring within the first string and returns it as a Result, or errors
lenstrINNULLOUTReturns the length of the string
trimINNULLOUTRemoves leading and trailing whitespace from the string
copyfromININOUTTreats the first argument as an array, the second argument as an index, and makes a duplicate of the array's nth element and stores it in the output argument (UNSAFE)
copytofINININTreats the first argument as an array, the second argument as an index, and the third argument as the address of fixed data and stores that fixed data in the array at the specified index (UNSAFE)
copytovINININTreats the first argument as an array, the second argument as an index, and the third argument as the address of an array of data and stores a copy of that second array within the first array at the specified address (UNSAFE)
registerININOUTTreats the first argument as an array, the second argument as an index, and places a pointer to the array's nth element and stores it in the output argument (UNSAFE)
newarrINNULLOUTCreates a new array of the specified initial size and stores it at the output address
pusharrINININTreats the first argument as an array, the second argument as the address of a value, and the third argument as a flag on whether the value is a fixed or array type, and pushes a duplicate of that value into the array
poparrINNULLOUTPops the last element off of the specified array and returns it in a Result object, or returns an error if the array is empty
lenarrINNULLOUTReturns the length of the array
indarrfININOUTTreats the first argument as an array, the second argument as a fixed value, and returns a result-wrapped index the value is first seen in the array, or an error
indarrvININOUTTreats the first argument as an array, the second argument as an array value, and returns a result-wrapped index the value is first seen in the array, or an error
joinININOUTTreats the first argument as an array of strings, the second argument as a string, and returns a new string where the string array elements are joined together with the second argument in between
mapINEVENTOUTTreats the first argument as an array and the second argument as an event ID that a single event handler should be registered to (it will only trigger the first one). It then has that handler mutate the array one element at a time and returns the results as a new array. Done in parallel if the array is large enough.
maplINEVENTOUTTreats the first argument as an array and the second argument as an event ID that a single event handler should be registered to (it will only trigger the first one). It then has that handler mutate the array one element at a time and returns the results as a new array. Done sequentially.
reparrININOUTTreats the first argument as an array and creates a new array made up with n duplicates based on the value of the second argument
eachINEVENTNULLTreats the first argument as an array and the second argument as an event ID, which it then executes for each element of the array in any order.
eachlINEVENTNULLTreats the first argument as an array and the second argument as an event ID, which it then executes for each element sequentially
findINEVENTOUTTreats the first argument as an array and the second argument as an event ID, which it then executes in parallel to find the first value that passes the test of the second argument and returns Result-wrapped, or errors. Still returns the first such value in the array, not the first encountered.
findlINEVENTOUTTreats the first argument as an array and the second argument as an event ID, which it then executes sequentially to find the first value that passes the test of the second argument and returns Result-wrapped, or errors.
everyINEVENTOUTTreats the first argument as an array and tests every element with the second argument in parallel, and returns true only if all elements return true.
everylINEVENTOUTTreats the first argument as an array and tests every element with the second argument sequentially, and returns true only if all elements return true.
someINEVENTOUTTreats the first argument as an array and tests every element with the second argument in parallel, and returns true if any element return true.
somelINEVENTOUTTreats the first argument as an array and tests every element with the second argument sequentially, and returns true if any element return true.
filterINEVENTOUTTreats the first argument as an array and test every element with the second argument in parallel, putting the element in the new array if it passes the test
filterlINEVENTOUTTreats the first argument as an array and test every element with the second argument sequentially, putting the element in the new array if it passes the test
reducelINEVENTOUTTreats the first argument as an array and the second argument as an event ID, which it executes sequentially to combine array elements together (maintaining the same type throughout) and finally returning the combined form
reducepINEVENTOUTTreats the first argument as an array and the second argument as an event ID, which it executes in parallel to combine array elements together (maintaining the same type throughout) and finally returning the combined form. Requires the reducer function to be commutative.
foldlINEVENTOUTTreats the first argument as a special array that houses the actual array in the first address and the initial value to reduce with in the second address. This allows for the output to store as a new type, with the initial value being of the same type as the output. The second argument has the event ID to perform the reduction with and this is executed sequentially.
foldpINEVENTOUTTreats the first argument as a special array that houses the actual array in the first address and the initial value to reduce with in the second address. This allows for the output to store as a new type, with the initial value being of the same type as the output. The second argument has the event ID to perform the reduction with and this is executed in parallel. This means the initial value will be merged in one OR MORE times and therefore the merging operation with that value must be idempotent, and the reducer function must be commutative.
catarrININOUTCreates a new array consisting first of the elements of the first array and second of the elements of the second array.
condfnINEVENTNULLUses the first argument as a boolean to check if the second argument, an event ID, should be executed or not
copyi8INNULLOUTCopies the i8 to a new address
copyi16INNULLOUTCopies the i16 to a new address
copyi32INNULLOUTCopies the i32 to a new address
copyi64INNULLOUTCopies the i64 to a new address
copyvoidINNULLOUTCopies the void to a new address
copyf32INNULLOUTCopies the f32 to a new address
copyf64INNULLOUTCopies the f64 to a new address
copyboolINNULLOUTCopies the bool to a new address
copystrINNULLOUTCopies the str to a new address
copyarrINNULLOUTCopies the array to a new address
zeroedNULLNULLOUTBlanks the specified address
lnf64INNULLOUTExecutes a trigonometric ln on the f64
logf64INNULLOUTExecutes a trigonometric log on the f64
sinf64INNULLOUTExecutes a trigonometric sin on the f64
cosf64INNULLOUTExecutes a trigonometric cos on the f64
tanf64INNULLOUTExecutes a trigonometric tan on the f64
asinf64INNULLOUTExecutes a trigonometric asin on the f64
acosf64INNULLOUTExecutes a trigonometric acos on the f64
atanf64INNULLOUTExecutes a trigonometric atan on the f64
sinhf64INNULLOUTExecutes a trigonometric sinh on the f64
coshf64INNULLOUTExecutes a trigonometric cosh on the f64
tanhf64INNULLOUTExecutes a trigonometric tanh on the f64
errorINNULLOUTTurns the specified error message into an Error type
noerrNULLNULLOUTCreates an empty non-error Error
errorstrINNULLOUTExtracts the error message from the Error
someMINNULLOUTWraps the provided value in a Maybe type
noneMNULLNULLOUTCreates an empty Maybe
isSomeINNULLOUTTests if the Maybe has a value
isNoneINNULLOUTTests if the Maybe has no value
getOrMININOUTExtracts the value from the Maybe in the first argument, or returns the default value in the second argument
okRINNULLOUTWraps the provided value in a Result type
errINNULLOUTWraps the provided error message in a Result type
isOkINNULLOUTTests if the Result has a successful value
isErrINNULLOUTTests if the Result has an error value
getOrRININOUTReturns the Result-wrapped value or the default value
getOrRSININOUTReturns the Result-wrapped string or the default string (workaround for kink involving strings in global memory)
getRINNULLOUTReturns the Result-wrapped value or crashes the runtime (UNSAFE)
getErrININOUTReturns the Result-wrapped error or a default error value
resfromININOUTLooks up the value of the index (second argument of the array (first argument) and returns that value Result-wrapped, or returns a Result-wrapped error
mainEINNULLOUTCreates an Either-wrapped main value
altEINNULLOUTCreates an Either-wrapped alternate value
isMainINNULLOUTTests if the Etiher is a main value
isAltINNULLOUTTests if the Either is an alternate value
mainOrININOUTReturns the Either-wrapped main value or the default value
altOrININOUTReturns the Either-wrapped alt value or the default value
hashfINNULLOUTReturns the 64-bit hash of the specified fixed value
hashvINNULLOUTReturns the 64-bit hash of the specified array value
dssetfINININStores the specified fixed value (third argument) in the namespace (first argument) and key (second argument) pair
dssetvINININStores the specified array value (third argument) in the namespace (first argument) and key (second argument) pair
dshasININOUTChecks the namespace (first argument) and key (second argument) pair for the presence of a value
dsdelININOUTChecks the namespace (first argument) and key (second argument) pair for the presence of a value and returns that status. If there was a value it also removes it.
dsgetfININOUTReturns a Result-wrapped fixed value (or error) for the specified namespace-key pair
dsgetvININOUTReturns a Result-wrapped array value (or error) for the specified namespace-key pair
httpgetINNULLOUTReturns a Result-wrapped string (or error) for the specified URL request
httppostININOUTReturns a Result-wrapped string (or error) for the specified post URL and body
httplsnINNULLOUTStarts an HTTP server on the specified port and returns a Result-wrapped 'ok' string or an Error
httpsendINNULLOUTFor a given connection response payload, send that payload to the client requesting it and returns a Result-wrapped 'ok' string or an Error if it failed
waitopINNULLNULLWaits the specified number of milliseconds, then continues execution
execopINNULLOUTExecutes the specified shell string and returns the exit code and stdout and stderr strings in an array
stdoutpINNULLNULLWrites the specified string to standard output
exitopINNULLNULLTerminates the process with the specified exit code