CPUSim64 Library Reference

The CPUSim64 comes with many library functions to make programming in CPU64 assembly easier. These functions are defined in .asm files and included using the #include preprocessor directive. Functions use stack-based calling conventions for arguments and return a value in R0 or F0.

Libraries also contain macros that use register-based calling conventions. Macros are defined in .def files along with the definitions for interrupts used by that library. When invoking macros, there is no guarantee that the registers R0, R1, R2, F0, F1 or F2 will be preserved. Most macros return a value in R0 or F0.

<system/ansi_color.asm>

This file defines control sequences for controlling an ANSI 16-Color Terminal. These symbols are labels for strings that you can send to the console using iPUTS or puts().

LabelDescription
ANSI_COLOR$RESETResets all styles and colors
ANSI_COLOR$BOLDSets bold style
ANSI_COLOR$DIMSets dim/faint style
ANSI_COLOR$ITALICSets italic style
ANSI_COLOR$UNDERLINESets underline style
ANSI_COLOR$BLINKSets blinking style
ANSI_COLOR$REVERSESets reversed style
ANSI_COLOR$HIDDENSets hidden style
ANSI_COLOR$STRIKETHROUGHSets strikethrough style
ANSI_COLOR$RESET_BOLD_DIMResets only the bold or dim style
ANSI_COLOR$RESET_UNDERLINEResets only the underline style
ANSI_COLOR$RESET_REVERSEResets only the reversed style
ANSI_COLOR$RESET_COLORResets only the foreground color
ANSI_COLOR$RESET_BGResets only the background color
ANSI_COLOR$BLACKSet foreground color to black
ANSI_COLOR$REDSet foreground color to red
ANSI_COLOR$GREENSet foreground color to green
ANSI_COLOR$YELLOWSet foreground color to yellow
ANSI_COLOR$BLUESet foreground color to blue
ANSI_COLOR$MAGENTASet foreground color to magenta
ANSI_COLOR$CYANSet foreground color to cyan
ANSI_COLOR$WHITESet foreground color to white
ANSI_COLOR$BRIGHT_BLACKSet foreground color to bright black
ANSI_COLOR$BRIGHT_REDSet foreground color to bright red
ANSI_COLOR$BRIGHT_GREENSet foreground color to bright green
ANSI_COLOR$BRIGHT_YELLOWSet foreground color to bright yellow
ANSI_COLOR$BRIGHT_BLUESet foreground color to bright blue
ANSI_COLOR$BRIGHT_MAGENTASet foreground color to bright magenta
ANSI_COLOR$BRIGHT_CYANSet foreground color to bright cyan
ANSI_COLOR$BRIGHT_WHITESet foreground color to bright white
ANSI_COLOR$BG_BLACKSet background color to black
ANSI_COLOR$BG_REDSet background color to red
ANSI_COLOR$BG_GREENSet background color to green
ANSI_COLOR$BG_YELLOWSet background color to yellow
ANSI_COLOR$BG_BLUESet background color to blue
ANSI_COLOR$BG_MAGENTASet background color to magenta
ANSI_COLOR$BG_CYANSet background color to cyan
ANSI_COLOR$BG_WHITESet background color to white
ANSI_COLOR$BG_BRIGHT_BLACKSet background color to bright black
ANSI_COLOR$BG_BRIGHT_REDSet background color to bright red
ANSI_COLOR$BG_BRIGHT_GREENSet background color to bright green
ANSI_COLOR$BG_BRIGHT_YELLOWSet background color to bright yellow
ANSI_COLOR$BG_BRIGHT_BLUESet background color to bright blue
ANSI_COLOR$BG_BRIGHT_MAGENTASet background color to bright magenta
ANSI_COLOR$BG_BRIGHT_CYANSet background color to bright cyan
ANSI_COLOR$BG_BRIGHT_WHITESet background color to bright white

<system/debug.def>

These debug macros only compile into your code if the assembler is passed the --DEBUG option. This allows you to retain debugging instructions and still create "non-debug" code that doesn't have the debugging instructions present just by omitting the --DEBUG option.

MacroDescription
DEBUG_MSGDEBUG_MSG(fmt, ...)
Formats a printf-style format string using the variable number of arguments supplied and prints it as a debug message.
COND_DEBUG_MSGCOND_DEBUG_MSG(cond, fmt, ...)
Formats a prinf-style format string using the variable number of arguments supplied and prints it as a debug message if the argument cond is true, otherwise it prints nothing.
PRINTCPUPRINTCPU
Prints the current state of the CPU.
SET_EXIT_ON_ASSERT_FAILURESET_EXIT_ON_ASSERT_FAILURE(b)
Sets the mode for asserts. If the argument b is true, assert macros will print message and then exit the program if they fail. Otherwise assert macros will print a message if they fail but not exit. Default is true.
ASSERT_TRUEASSERT_TRUE(isTrue, message)
Asserts that a condition is true. Prints the message if the assertion fails.
ASSERT_FALSEASSERT_FALSE(isFalse, message)
Asserts that a condition is false. Prints the message if the assertion fails.
ASSERT_EQASSERT_EQ(expected, actual, message)
Asserts that integer values expected and actual are equal. Prints the message if the assertion fails.
ASSERT_NEASSERT_NE(expected, actual, message)
Asserts that integer values expected and actual are not equal. Prints the message if the assertion fails.
ASSERT_GTASSERT_GT(expected, actual, message)
Asserts that integer value expected is greater than actual. Prints the message if the assertion fails.
ASSERT_LTASSERT_LT(expected, actual, message)
Asserts that integer value expected is less than actual. Prints the message if the assertion fails.
ASSERT_GEASSERT_GE(expected, actual, message)
Asserts that integer value expected is greater than or equal to actual. Prints the message if the assertion fails.
ASSERT_LEASSERT_LE(expected, actual, message)
Asserts that integer value expected is less than or equal to actual. Prints the message if the assertion fails.
ASSERT_EQ_FPASSERT_EQ_FP(expected, actual, message)
Asserts that floating point values expected and actual are equal. Prints the message if the assertion fails.
ASSERT_NE_FPASSERT_NE_FP(expected, actual, message)
Asserts that floating point values expected and actual are not equal. Prints the message if the assertion fails.
ASSERT_GT_FPASSERT_GT_FP(expected, actual, message)
Asserts that floating point value expected is greater than actual. Prints the message if the assertion fails.
ASSERT_LT_FPASSERT_LT_FP(expected, actual, message)
Asserts that floating point value expected is less than actual. Prints the message if the assertion fails.
ASSERT_GE_FPASSERT_GE_FP(expected, actual, message)
Asserts that floating point value expected is greater than or equal to actual. Prints the message if the assertion fails.
ASSERT_LE_FPASSERT_LE_FP(expected, actual, message)
Asserts that floating point value expected is less than or equal to actual. Prints the message if the assertion fails.

The floating point assertion macros require that both float values be registers. The integer assertion macros can use a register or a literal for the values.

<system/io.def>

These are the I/O macros defined for CPUSim64.

MacroDescription
IN0IN0(register,port)
Reads one Unicode codepoint from the port.
IN1IN1(register,port)
Reads one byte from the port.
IN2IN2(register,port)
Reads one 2 byte short word from the port.
IN4IN4(register,port)
Reads one 4 byte word from the port.
IN8IN8(register,port)
Reads one 8 byte long word from the port.
OUT0OUT0(register, port)
Writes one Unicode codepoint to the port.
OUT1OUT1(register, port)
Writes one byte to the port.
OUT2OUT2(register, port)
Writes one 2 byte short word to the port.
OUT4OUT4(register, port)
Writes one 4 byte word to the port.
OUT8OUT8(register, port)
Writes one 8 byte long to the port.
PUT_NLPUT_NL()
Writes the newline character(s) to STDOUT.
PUTSPUTS(str)
Writes the UTF-8 string pointed to by str to STDOUT.
PUT_INTPUT_INT(val, base)
Writes the integer val to STDOUT using the specified base.
PUT_DECPUT_DEC(val)
Writes the integer to STDOUT in base 10.
PUT_HEXPUT_HEX(val)
Writes the integer to STDOUT in base 16.
PUT_FPPUT_FP(val, prec)
Writes the float to STDOUT.

<system/io.asm>

These are the I/O functions defined for CPUSim64.

FunctionDescription
fgetlinefgetline(port, buffer)
Read an entire line of text input from the port. The buffer argument points to a heap allocated buffer. Returns 0 on EOF or error. Returns buffer or perhaps a reallocated heap block. Must free when done with buffer.
put_nlput_nl()
Thread safe output of the newline character(s) to STDOUT.
fput_nlfput_nl(port)
Non-thread safe output of the newline character(s) to the port.
putcputc(cp)
Thread safe output of the Unicode codepoint to STDOUT.
fputcfputc(port, cp)
Non-thread safe output of the Unicode codepoint to the port.
putsputs(str)
Thread safe output of the UTF-8 string pointed to by str to STDOUT.
fputsfputs(port, str)
Non-thread safe output of the UTF-8 string pointed to by str to the port.
putlineputline(str)
Thread safe output of the UTF-8 string pointed to by str to STDOUT with a newline appended.
fputlinefputline(port, str)
Non-thread safe output of the UTF-8 string pointed to by str to STDOUT with a newline appended.
put_intput_int(value, base)
Thread safe output of the integer value to STDOUT using the specified base.
fput_intfput_int(port, value, base)
Non-thread safe output of the integer value to the port using the specified base.
put_decput_dec(value)
Thread safe output of the integer value to STDOUT using base 10.
fput_decfput_dec(port, value)
Non-thread safe output of the integer value to the port using base 10.
put_hexput_hex(value)
Thread safe output of the integer value to STDOUT using base 16.
fput_hexfput_hex(port, value)
Non-thread safe output of the integer value to the port using base 16.
put_hex_sizeput_hex_size(value, size)
Thread safe output of the integer value to STDOUT using base 16. Outputs at least size digits by padding with 0.
fput_hex_sizefput_hex_size(port, value, size)
Non-thread safe output of the integer value to the port using base 16. Outputs at least size digits by padding with 0.
put_fpput_fp(value, prec)
Thread safe output of the float value to STDOUT. Output is rounded to prec significant digits.
fput_fpfput_fp(port, value, prec)
Non-thread safe output of the float value to the port. Output is rounded to prec significant digits.
printfprintf(fmt, values...)
Thread safe output of the format string pointed to by fmt using values to STDOUT. Format specifiers include: %s, %c, %d, %x and %f.
fprintffprintf(port, fmt, values...)
Non-thread safe output of the format string pointed to by fmt using values to port. Format specifiers include: %s, %c, %d, %x and %f.
cond_printfcond_printf(cond, fmt, values...)
Thread safe output of the format string pointed to by fmt using values to STDOUT only if cond is true. Format specifiers include: %s, %c, %d, %x and %f.
cond_fprintfcond_fprintf(cond, port, fmt, values...)
Non-thread safe output of the format string pointed to by fmt using values to port only if cond is true. Format specifiers include: %s, %c, %d, %x and %f.
fatalfatal(fmt, values...)
Thread safe output of the format string pointed to by fmt using values to STDERR. Format specifiers include: %s, %c, %d, %x and %f. After output the program is terminated.
cond_fatalprintf(cond, fmt, values...)
Thread safe output of the format string pointed to by fmt using values to STDERR only if cond is true. Format specifiers include: %s, %c, %d, %x and %f. If cond is true the program is terminated.
opentTextFileopenTextFile(filename, mode)
Opens the text file specified by filename using mode (READ_MODE, WRITE_MODE or APPEND_MODE). A non-negative port number is returned if successful whereas -1 on error. Reading or writing to text files will convert between operating system specific newlines and the newline ('\n') character.
opentRawFileopenRawFile(filename, mode)
Opens the raw file specified by filename using mode (READ_MODE, WRITE_MODE or APPEND_MODE). A non-negative port number is returned if successful whereas -1 on error. Reading or writing to raw files will not perform any newline conversions.
close_fileclose_file(port)
Closes the port specified and makes it available for reuse.
flushflush(port)
Flushes buffered writes to the port.
deleteFiledeleteFile(filespec)
Deletes the file specified by the pointer to UTF-8 string filespec.
makeDirectorymakeDirectory(path)
Creates the directory specified by the pointer to UTF-8 string path.
deleteDirectorydeleteDirectory(path)
Deletes the directory (if empty) specified by the pointer to UTF-8 string path.
isDirectoryisDirectory(path)
Returns true if the path specified by the pointer to UTF-8 string path is a directory.
deleteFilesdeleteFiles(strList)
Deletes the files specified in the list of pointers to UTF-8 strings.
listFileslistFiles(path)
Returns a heap allocated list of UTF-8 strings for the files in directory specified by the pointer to UTF-8 string path.
isFileisFile(path)
Returns true if the path specified by the pointer to UTF-8 string path is a regular file.
fileExistsfileExists(path)
Deletes the file specified by the pointer to UTF-8 string path.
tempDirectorytempDirectory(prefix)
Returns a heap allocated UTF-8 string with a valid temporary directory location using prefix at the beginning of the directory name.
tempFiletempFile(prefix, suffix)
Returns a heap allocated UTF-8 string with a valid temporary file location using prefix at the beginning of the file name and suffix at the end.
copy_text_filecopy_text_file(fromPort, toPort)
Copies the text file from the open port fromPort to the open port toPort.
copy_raw_filecopy_raw_file(fromPort, toPort)
Copies the raw file from the open port fromPort to the open port toPort.
printIntegerArrayAsListprintIntegerArrayAsList(addrArg)
Prints the array of integers to STDOUT as a comma separated list.
printFloatArrayAsListprintFloatArrayAsList(addrArg)
Prints the array of floats to STDOUT as a comma separated list.
printStringArrayAsListprintStringArrayAslist(addrArg)
Prints the array of UTF-8 strings to STDOUT as a comma separated list.

<system/math.def>

MacroDescription
MINMIN(a, b)
Returns in R0 the smaller of integers a or b.
MAXMAX(a, b)
Returns in R0 the larger of integers a or b.
FMINFMIN(a, b)
Returns in F0 the smaller of float a or b.
FMAXFMAX(a, b)
Returns in F0 the larger of float a or b.

<system/math.asm>

These are the math functions defined for CPUSim64. Integer arguments can be general purpose registers or integer constants. They are indicated by arguments named i, j, k, etc. Floating point arguments must be floating point registers. Floating point arguments are indicated using names x, y, z, a, b, c, etc.

FunctionDescription
absabs(i)
Returns in R0 the absolute value of the integer i.
acosacos(x)
Returns inverse cosine of x as radians.
asinasin(x)
Returns inverse sine of x as radians.
atanatan(x)
Returns inverse tangent of x as radians.
atan2atan2(x, y)
Returns inverse tangent of x/y as radians even if denom is 0.
ceilceil(x)
Returns in F0 the smallest integer greater than float x.
coscos(x)
Returns cosine of x (in radians).
expexp(x)
Returns in F0 the value e^x.
exp10exp10(x)
Returns in F0 the value 10.^x.
exp2exp2(x)
Returns in F0 the value 2.^x.
fabsfabs(x)
Returns in F0 the absolute value of the float x.
fastpowfastpow(x, j)
Returns in F0 the value x^j using fast exponentiation algorithm.
floorfloor(x)
Returns in F0 the largest integer less than float x.
fmaxfmax(a, b)
Returns in F0 the larger of float a or b.
fminfmin(a, b)
Returns in F0 the smaller of float a or b.
fsumfsum(array)
Returns in F0 the sum of the floats at address array. First element of array is the array size.
idividiv(i, j)
Returns in R0 the integer result of i/j.
ifastpowifastpow(i, j)
Returns in R0 the value i^j using fast exponentiation algorithm.
ln_baseln_base()
Returns in F0 the base of the natural logarithm e.
loglog(x)
Returns in F0 the natural logarithm of x.
log10log10(x)
Returns in F0 the common logarithm of x.
log2log2(x)
Returns in F0 the binary logarithm of x.
maxmax(i, j)
Returns in R0 the larger of integers a or b.
minmin(i, j)
Returns in R0 the smaller of integers a or b.
modmod()
modmod(i, j)
Returns in R0 the remainder after division of i/j.
pipi()
Returns in F0 the mathematics constant π.
powpow(x, y)
Returns in F0 the value x^y.
randrand(i, j)
Returns in R0 a random value in the range [i,j].
randomrandom()
Returns in F0 a random value in the range [0.0, 1.0).
remainderremainder(num, denom)
>Returns the fractional portion of num / denom using IEEE 754 remainder rules.
roundround(x)
Returns in F0 the nearest integer to float x. It rounds down if the decimal part is less than 0.5 and rounds up if it is 0.5 or greater.
sinsin(x)
Returns sine of x (in radians).
sqrtsqrt(x)
Returns in F0 the square root of float x.
sumsum(array)
Returns in R0 the sum of the integers at address array. First element of array is the array size.
tantan(x)
Returns tangent of x (in radians).
to_degreesto_degrees(x)
>Returns float converted from radians to degrees.
to_radiansto_radians(x)
Returns float converted from degrees to radians.

<system/string.def>

These are the string macros defined for CPUSim64.

MacroDescription
FMT_DECFMT_DEC(x)
Formats the value x as a base-10 (decimal) string.
FMT_HEXFMT_HEX(x)
Formats the value x as a hexadecimal string.
FMT_FLOATFMT_FLOAT(x)
Formats the value x as a floating-point string.
PARSE_INTPARSE_INT(x)
Parses string x and converts it to an integer using automatic base detection.
PARSE_DECPARSE_DEC(x)
Parses decimal string x and converts it to an integer.
PARSE_HEXPARSE_HEX(x)
Parses hexadecimal string x and converts it to an integer.
PARSE_FLOATPARSE_FLOAT(x)
Parses string x and converts it to a floating-point value.
TO_LOWERTO_LOWER(x)
Converts a single codepoint x to lowercase.
TO_UPPERTO_UPPER(x)
Converts a single codepoint x to uppercase.
TO_LOWER_STRTO_LOWER_STR(x)
Returns a lowercase version of string x as a heap allocated string.
TO_UPPER_STRTO_UPPER_STR(x)
Returns an uppercase version of string x as a heap allocated string.
STRLENSTRLEN(s1)
Returns the number of characters in string s1.
STRCOPYSTRCOPY(s1)
Creates and returns a heap allocated copy of string s1.
STRCMPSTRCMP(s1, s2)
Compares strings s1 and s2 lexicographically. Returns negative integer if s1 < s2, 0 if equal, and a positive integer if s1 > s2.
STRICMPSTRICMP(s1, s2)
Compares strings s1 and s2 lexicographically in a case-insensitive manner. Returns negative integer if s1 < s2, 0 if equal, and a positive integer if s1 > s2.
SUBSTRINGSUBSTRING(s, start, length)
Extracts a substring from s starting at start with the specified length.
PREFIXPREFIX(s, length)
Returns the first length characters of string s.
SUFFIXSUFFIX(s, length)
Returns the last length characters of string s.
CHAR_SEARCHCHAR_SEARCH(s, char, startpos)
Finds the first occurrence of codepoint char in s starting at startpos.
LAST_CHAR_SEARCHLAST_CHAR_SEARCH(s, char, startpos)
Finds the last occurrence of codepoint char in s starting at startpos and searching backward.
SUBSTRING_SEARCHSUBSTRING_SEARCH(s, substr, startpos)
Finds the first occurrence of substr in s starting at startpos.
LAST_SUBSTRING_SEARCHLAST_SUBSTRING_SEARCH(s, substr, startpos)
Finds the last occurrence of substr in s starting at startpos and searching backward.
STARTS_WITHSTARTS_WITH(str, prefix)
Checks to see if the string begins with prefix.
ENDS_WITHENDS_WITH(str, suffix)
Checks to see if the string ends with suffix.
GET_CODEPOINTSGET_CODEPOINTS(str)
Returns an array of Unicode codepoints from string str.
FROM_CODEPOINTSFROM_CODEPOINTS(arr)
Creates a heap allocated string from an array of Unicode codepoints.
COUNT_GLPYHSCOUNT_GLPYHS(str)
Returns the number of user-visible glyphs in string str.
HASH_CODEHASH_CODE(str)
Computes and returns a hash value for string str.
TRIMTRIM(str)
Removes leading and trailing whitespace from string str.
MATCHESMATCHES(str, pattern)
Checks whether str matches the given regex pattern.
REPLACE_FIRSTREPLACE_FIRST(str, pattern, replacement)
Replaces the first occurrence of regex pattern in str with replacement.
REPLACE_ALLREPLACE_ALL(str, pattern, replacement)
Replaces all occurrences of regex pattern in str with replacement.
SPLITSPLIT(str, delimiter)
Splits str into an heap allocated array using delimiter.
JOINJOIN(arr, delimiter)
Joins array arr into a heap allocated string using delimiter.
STRCATSTRCAT(s1, s2)
Concatenates strings s1 and s2 and returns the heap allocated result.

<system/string.asm>

These are the string functions defined for CPUSim64.

FunctionDescription
printStringArrayprintStringArray(a)
Prints an array of UTF-8 strings with the index and value.
freeStrArrayfreeStrArray(addArg)
Frees the heap allocated array containing heap allocated strings.
sprintfsprintf(fmt, values...)
Returns a heap allocated string with the values applied to the format string fmt. Format specifiers include: %s, %c, %d, %x and %f.
formatformat(fmt, values...)
Returns a heap allocated string with the values applied to the format string fmt. Format specifiers include: {}, {0}, {1}, etc.

<system/system.def>

These are the system macros defined for CPUSim64.

MacroDescription
TO_BOOLEANTO_BOOLEAN(x)
Returns TRUE or FALSE depending on the truthiness of x. Truthiness is false for zero and true for non-zero.
TO_NOT_BOOLEANTO_NOT_BOOLEAN(x)
Returns TRUE or FALSE depending on the not-truthiness of x. Truthiness is false for zero and true for non-zero.
COMPARECOMPARE(x, op, y)
Compares x to y using operator op. Status register will be set according to the comparison.
COMPARE_RANGECOMPARE_RANGE(low, op1, x, op2, high)
Compares x to low and high using operators op1 and op2. Status register will be set according to the comparison.
ALLOCALLOC(size)
Allocates a heap block of size long words. Returned address must eventually be freed.
REALLOCREALLOC(addr, size)
Reallocates heap block at addr to size long words. May return addr or a new address of a larger heap block.
FREEFREE(addr)
Releases the heap allocated memory at the address addr.
FREE_ELEMENTFREE_ELEMENT(a, offset)
Releases the heap allocated memory using the address in array element a[offset].
ALLOC_SHAREDALLOC_SHARED(size)
Allocates size long words in the shared memory area. This memory can not be freed.
MEMMOVEMEMMOVE(dest, src, count)
Moves count long words from src to dest. Handles overlapping memory.
MEMCLEARMEMCLEAR(dest, count)
Sets the memory to 0 starting at address dest for count long words.
SLEEPSLEEP(ms)
Puts the current thread to sleep for ms milliseconds.

<system/system.asm>

These are the system functions defined for CPUSim64.

FunctionDescription
printIntegerArrayprintIntegerArray(a)
Prints an array of integers with the index and value.
printFloatArrayprintFloatArray(a)
Prints an array of floats with the index and value.
memmovememmove(dest, src, count)
Moves count long words from src to dest. Handles overlapping memory.
memclearmemclear(dest, count)
Sets the memory to 0 starting at address dest for count long words.
sleepsleep(ms)
Puts the current thread to sleep for ms milliseconds.
exitexit(code)
Terminates the program returning the code value to the operating system.
systemsystem(cmd)
Executes the shell command specified in the UTF-8 string cmd.
allocalloc(size)
Allocates a heap block of size long words. Returned address must eventually be freed.
reallocrealloc(addr, size)
Reallocates heap block at addr to size long words. May return addr or a new address of a larger heap block.
freefree(addr)
Releases the heap allocated memory at the address addr.
freeElementfreeElement(addr, offset)
Releases the heap allocated memory using the address in array element a[offset].
argsargs(index)
Returns the command line argument specified by index. Name of the program is in index 0. Command line arguments start at index 1.
mutexLockmutexLock(addr, timeout)
Pauses the current thread until the mutex at addr can be acquired or until timeout is reached. Timeout is in milliseconds. Use -1 for no timeout. Returns TRUE if successful.
mutexLockElementmutexLockElement(addr, offset, timeout)
auses the current thread until the mutex at addr[offset] can be acquired or until timeout is reached. Timeout is in milliseconds. Use -1 for no timeout. Returns TRUE if successful.
mutexUnlockmutexUnlock(addr)
Unlocks the mutex at addr. Returns TRUE if successful.
mutexUnlockElementmutexUnlockElement(addr, offset)
Unlocks the mutex at addr[offset]. Returns TRUE if successful.

<system/thread.def>

These are the thread macros defined for CPUSim64.

MacroDescription
DEFINE_SPINLOCKDEFINE_SPINLOCK(name)
Allocates a spinlock with the specified name in the global data area.
DEFINE_SHARED_SPINLOCKDEFINE_SHARED_SPINLOCK(name)
Allocates a spinlock in the shared memory area. Stores the address of the spinlock in the variable with the specified name in the global data area.
DEFINE_RECURSIVE_SPINLOCKDEFINE_RECURSIVE_SPINLOCK(name)
Allocates a recursive spinlock with the specified name in the global data area.
DEFINE_SHARED_RECURSIVE_SPINLOCKDEFINE_SHARED_RECURSIVE_SPINLOCK(name)
Allocates a recursive spinlock in the shared memory area. Stores the address of the recursive spinlock in the variable with the specified name in the global data area.
DEFINE_MUTEXDEFINE_MUTEX(name)
Allocates a mutex with the specified name in the global data area.
DEFINE_SHARED_MUTEXDEFINE_SHARED_MUTEX(name)
Allocates a mutex in the shared memory area. Stores the address of the mutex in the variable with the specified name in the global data area.
CREATE_THREADCREATE_THREAD(entryPoint, data)
Creates a thread that runs the code at entryPoint and passed the address of a data block at data. Returns thread PID of the new thread in R0 or -1 on error.
JOIN_THREADJOIN_THREAD(threadPID)
Pauses the execution of the current thread until the thread with PID threadPID terminates.
WAKE_THREADWAKE_THREAD(threadPID)
Wakes the thread with PID threadPID.

<system/thread.asm>

These are the thread functions defined for CPUSim64.

Initializes the mutex at address addr.
FunctionDescription
initializeSpinLockinitializeSpinLock(addr)
Initializes the spinlock at address addr.
acquireSpinLockacquireSpinLock(addr)
Pauses the current thread until it can acquire the spinlock at address addr.
releaseSpinLockreleaseSpinLock(addr)
Release the spinlock at address addr.
initializeRecursiveSpinLockinitializeRecursiveSpinLock(addr)
Initializes the recursive spinlock at address addr.
acquireRecursiveSpinLockacquireRecursiveSpinLock(addr)
Pauses the current thread until it can acquire the recursive spinlock at address addr.
releaseRecursiveSpinLockreleaseRecursiveSpinLock(addr)
Release the recursive spinlock at address addr.
initializeMutexinitializeMutex(addr)
acquireMutexacquireMutex(addr)
Pauses the current thread until it can acquire the mutex at address addr.
releaseMutexreleaseMutex(addr)
Release the mutex at address addr.
get_and_incrementget_and_increment(addr)
Atomically increments the value at addr. Returns the new value.
get_and_decrementget_and_decrement(addr)
Atomically decrements the value at addr. Returns the new value.