The CPUSim64 comes with many functions defined as part of its operating system. These functions are accessed via software interrupts. To access the defines that give symbolic names to the interrupt values you must include the appropriate system include file.
Input to interrupt functions is passed through known registers. Output is usually in either r0
or f0
if the function returns a value.
When invoking interrupts, there is no guarantee that the operands will not be modified or that registers r0
or f0
will not be modified.
Interrupt | Pneumonic | Input Registers | Operation |
---|---|---|---|
200 | iPUT_NL | r0: output port | Outputs the newline character(s) to the output port. |
201 | iPUT_INT | r0: output port r1: output value r2: base | Converts the output value to a string using the specified base and outputs it to the specified port. |
202 | iPUT_DEC | r0: output port r1: output value | Converts the output value to a string using base 10 and outputs it to the specified port. |
203 | iPUT_HEX | r0: output port r1: output value | Converts the output value to a string using base 16 and outputs it to the specified port. |
204 | iPUT_FP | r0: output port f0: output value | Converts the output value to a string and outputs it to the specified port. |
205 | iPUTS | r0: output port r1: output string address | Outputs a string to the specified port. |
206 | iGET_INT | r0: input port r1: base | Gets string from the specified port and converts it to an integer using base. |
207 | iGET_DEC | r0: input port | Gets string from the specified port and converts it to an integer using base 10. |
208 | iGET_HEX | r0: input port | Gets string from the specified port and converts it to an integer using base 16. |
209 | iGET_FP | r0: input port | Gets string from the specified port and converts it to floating point. |
210 | iGETS | r0: input port r1: buffer to hold string | Gets string from the specified port. r1 will change if buffer is realloced to a larger size. |
211 | iPRINTF | Arg1: port Arg2: format string address Arg3: first value Arg4: second value ... | Stack-based interrupt that implements C-style printf(). Arguments are pushed in reverse order onto the stack. Return address and stack frame are expected to be pushed last which means this interrupt should only be used inside a called function like fprintf(). |
220 | iOPEN_FILE_READ | r0: port (3-15) r1: filepath string | Opens the file for text reading. |
221 | iOPEN_FILE_WRITE | r0: port (3-15) r1: filepath string | Opens the file for test writing. |
222 | iOPEN_FILE_APPEND | r0: port (3-15) r1: filepath string | Opens the file for text append. |
223 | iOPEN_RAW_FILE_READ | r0: port (3-15) r1: filepath string | Opens the file for raw read. |
224 | iOPEN_RAW_FILE_WRITE | r0: port (3-15) r1: filepath string | Opens the file for raw write. |
225 | iOPEN_RAW_FILE_APPEND | r0: port (3-15) r1: filepath string | Opens the file for raw append. |
226 | iCLOSE_FILE | r0: port | Closes the file on port. |
227 | iFLUSH | r0: port | Flushes output to the file on port. |
228 | iDELETE_FILE | r0: filepath string | Deletes the file specified. Returns TRUE if successful./td> |
229 | iMAKE_DIR | r0: path string | Creates the specified directory. Returns TRUE if successful./td> |
230 | iDELETE_DIR | r0: path string | Deletes the specified directory. Must be empty. Returns TRUE if successful./td> |
231 | iIS_DIR | r0: filepath string | Returns true if the specified filepath belongs to a directory. |
232 | iIS_FILE | r0: filepath string | Returns true if the specified filepath belongs to a file. |
233 | iFILE_EXISTS | r0: filepath string | Returns true if the specified filepath exists as a file or directory. |
234 | iFILES | r0: path string | Returns an array of strings containing the files/dirs residing in the path specified. |
235 | iTEMP_DIR | r0: prefix string | Returns an heap allocated string containing the name of a randomly generated tempory directory. Returns null on error. |
236 | iTEMP_FILE | r0: prefix string r1: extension string | Returns an heap allocated string containing the name of a randomly generated tempory filepath. Returns null on error. |
Interrupt | Pneumonic | Input Registers | Operation |
---|---|---|---|
100 | iPI | none | Returns the floating point constant π. |
101 | iE | none | Returns the floating point constant base of the natural logarithm. |
102 | iABS_FP | f0: value | Returns the absolute value of the floating point value. |
103 | iABS | r0: value | Returns the absolute value of the integer value. |
104 | iCEIL | f0: value | Returns the smallest whole number greater than or equal to value. |
105 | iFLOOR | f0: value | Returns the largest whole number less than or equal to value. |
106 | iROUND | f0: value | Returns the nearest whole number to value. |
107 | iSQRT | f0: value | Returns the square root of value. |
108 | iEXP | f0: value | Returns evalue. |
109 | iLOG | f0: value | Returns the natural logarithm of value. |
110 | iPOW | f0: base f1: exponent | Returns baseexponent |
111 | iREMAINDER | f0: num f1: denom | Returns the fractional portion of num / denom. |
112 | iMAX_FP | f0: value f1: value | Returns the larger of the two floating point values. |
113 | iMIN_FP | f0: value f1: value | Returns the smaller of the two floating point values. |
114 | iMAX | r0: value r1: value | Returns the larger of the two integer values. |
115 | iMIN | r0: value r1: value | Returns the larger of the two integer values. |
116 | iRANDOM | none | Returns a pseudorandom floating point greater than or equal to 0.0 and less than 1.0. |
117 | iRAND | r0: lower r1: upper | Returns a uniformly distributed random integer on the interval [lower,upper] |
118 | iTO_DEGREES | f0: value | Returns value converted from radians to degrees. |
119 | iTO_RADIANS | f0: value | Returns value converted from degrees to radians. |
120 | iSIN | f0: value in radians | Returns sin(value). |
121 | iCOS | f0: value in radians | Returns cos(value). |
122 | iTAN | f0: value in radians | Returns tan(value). |
123 | iASIN | f0: value | Returns arcsin(value) in radians. |
124 | iACOS | f0: value | Returns arccos(value) in radians. |
126 | iATAN | f0: value | Returns arctan(value) in radians. |
125 | iATAN2 | f0: num f1: denom | Returns arctan(num/denom) in radians even if denom is 0. |
Interrupt | Pneumonic | Input Registers | Operation |
---|---|---|---|
301 | iFMT_DEC | r0: value | Formats the integer value in decimal as a heap allocated string. |
302 | iFMT_HEX | r0: value | Formats the integer value in hexdecimal as a heap allocated string. |
303 | iFMT_FLOAT | f0: value | Formats the floating point value as a heap allocated string. |
304 | iPARSE_INT | r0: string address | Parses a string as decimal, hexadecimal (0x or # prefix) or octal (0 prefix) integer. |
305 | iPARSE_DEC | r0: string address | Parses a string as a decimal integer. |
306 | iPARSE_HEX | r0: string address | Parses a string as a hexadecimal integer. |
307 | iPARSE_FLOAT | r0: string address | Parses a string as a floating point value. |
308 | iSPRINTF | Arg1: port Arg2: format string address Arg3: first value Arg4: second value ... | Stack-based interrupt that implements C-style printf(). Arguments are pushed in reverse order onto the stack. Return address and stack frame are expected to be pushed last which means this interrupt should only be used inside a called function like sprintf(). |
309 | iTO_LOWER | r0: character | Returns the lowercase version of the character. |
310 | iTO_UPPER | r0: character | Returns the uppercase version of the character. |
311 | iTO_LOWER_STR | r0: string address | Returns lowercase version of string as a heap allocated string. |
312 | iTO_UPPER_STR | r0: string address | Returns uppercase version of string as a heap allocated string. |
313 | iSUBSTRING_SEARCH | r0: string to search r1: string to find | Searches a string for the specified substring and returns the index into the string if found or -1 if not found. |
314 | iLAST_SUBSTRING_SEARCH | r0: string to search r1: string to find | Searches a string from the end for the specified substring and returns the index into the string if found or -1 if not found. |
315 | iMATCHES | r0: string to search r1: regex to find | Searches a string for the specified regular expression and returns TRUE if found or FALSE if not found. |
316 | iREPLACE_FIRST | r0: string to search r1: regex to find r2: replacement string | Searches a string for the specified regular expression and returns the heap allocated string that has the first occurance replaced by the replacement string. |
317 | iREPLACE_ALL | r0: string to search r1: regex to find r2: replacement string | Searches a string for the specified regular expression and returns the heap allocated string that has all the occurances replaced by the replacement string. |
318 | iSPLIT | r0: string to split r1: split regex r2: limit | Splits the string using the regex returning an array of strings capped with maximum elements specified by limit. If limit is -1 the splitting is not capped. |
Interrupt | Pneumonic | Input Registers | Operation |
---|---|---|---|
1 | iINT_MIN | none | Returns largest negative integer. |
2 | iINT_MAX | none | Returns largest negative positive integer. |
3 | iFLOAT_MIN | none | Returns smallest floating point value greater than 0. |
4 | iFLOAT_MAX | none | Returns largest floating point value. |
5 | iNEGATIVE_INFINITY | none | Returns negative infinity. |
6 | iPOSITIVE_INFINITY | none | Returns positive infinity. |
7 | iNAN | none | Returns Not A Number. |
10 | iCYCLES | none | Returns user CPU time in cycles. |
11 | iCLOCK | none | Returns current execution time in ns. |
12 | iSAVE | none | Saves r0-r28 on the stack. |
13 | iSAVE_FP | none | Saves f0-f31 on the stack. |
14 | iRESTORE | none | Restores r0-r28 from the stack. |
15 | iRESTORE_FP | none | Restores f0-f31 from the stack. |
16 | iPrintCPUState | none | Prints a diagram of the current CPU state and stack. |
20 | iALLOC | r0: allocation size | Returns a heap allocated block address. |
21 | iREALLOC | r0: allocation address r1: new allocation size | Returns a new heap allocated block with data copied from the passed allocation address. The original allocation address is freed if it is in the heap. |
22 | iFREE | r0: allocation address | Returns the heap allocated block address to the free list. |
23 | iARGC | none | Returns the number of command line arguments. |
24 | iARGS | r0: argument index | Returns address of of the command line argument specified by index or null. Index 0 returns the program name. |
25 | iMEMMOVE | r0: dest address r1: src address r3: length | Moves contents of memory from src to dest. Can handle overlapping memory blocks. |
30 | iEXIT | r0: exit code | Exits process with specified code. |
31 | iSYSTEM | r0: string address | Executes the system command contained in the string. Returns the exit code of the command. |
32 | iFORK | ||
33 | iWAIT | ||
34 | iWAIT_PID | ||
35 | iTHREAD | ||
36 | iWAIT_THREAD | ||
37 | iSLEEP | r0: delay in ms | Pauses execution for the specified milliseconds. |