MIPS Syscalls
MIPS syscalls are used to make requests to the operating system. They are not instructions that are executed by the CPU, but rather instructions that are used by the simulator to make requests to the operating system.
Each syscall has a unique code that is used to identify it. You must put the syscall code inside the
the $v0 register before calling the syscall instruction.
As an example:
# Load the integer 42 into register $a0, which is
# the register that will be printed by the syscall
li $a0, 42
# Set the syscall code for printing an integer
li $v0, 1
syscall
1 - Print integer
Arguments
2 - Print float
Arguments
3 - Print double
Arguments
4 - Print string
Arguments
5 - Read integer
Result
6 - Read float
Result
7 - Read double
Result
8 - Read string
Service 8 - Follows semantics of UNIX 'fgets'. For specified length n, string can be no longer than n-1. If less than that, adds newline to end. In either case, then pads with null byte If n = 1, input is ignored and null byte placed at buffer address. If n < 1, input is ignored and nothing is written to the buffer.
Arguments
9 - Sbrk (allocate heap memory)
Result
Arguments
10 - Exit (terminate execution)
11 - Print character
Service 11 - Prints ASCII character corresponding to contents of low-order byte.
Arguments
12 - Read character
Result
13 - Open file
Service 13 - MARS implements three flag values: 0 for read-only, 1 for write-only with create, and 9 for write-only with create and append. It ignores mode. The returned file descriptor will be negative if the operation failed. MARS maintains file descriptors internally and allocates them starting with 3. File descriptors 0, 1 and 2 are always open for: reading from standard input, writing to standard output, and writing to standard error, respectively (new in release 4.3).
Result
Arguments
14 - Read from file
Services 13,14,15 - In MARS 3.7, the result register was changed to $v0 for SPIM compatability. It was previously $a0 as erroneously printed in Appendix B of Computer Organization and Design,.
Result
Arguments
15 - Write to file
Services 13,14,15 - In MARS 3.7, the result register was changed to $v0 for SPIM compatability. It was previously $a0 as erroneously printed in Appendix B of Computer Organization and Design,.
Result
Arguments
16 - Close file
Arguments
17 - Exit2 (terminate with value)
Service 17 - If the MIPS program is run under control of the MARS graphical interface (GUI), the exit code in $a0 is ignored.
Arguments
30 - Time (system time)
Service 30 - System time as milliseconds since 1 January 1970.
Result
34 - Print integer in hexadecimal
Displayed value is 8 hexadecimal digits, left-padding with zeroes if necessary.
Arguments
35 - Print integer in binary
Displayed value is 32 bits, left-padding with zeroes if necessary.
Arguments
36 - Print integer as unsigned
Displayed as unsigned decimal value.
Arguments
41 - Random int
Each stream (identified by $a0 contents) is modeled by a different Random object. There are no default seed values, so use the Set Seed service (40) if replicated random sequences are desired.
Result
Arguments
42 - Random int range
Each stream (identified by $a0 contents) is modeled by a different Random object. There are no default seed values, so use the Set Seed service (40) if replicated random sequences are desired.
Result
Arguments
43 - Random float
Each stream (identified by $a0 contents) is modeled by a different Random object. There are no default seed values, so use the Set Seed service (40) if replicated random sequences are desired.
Result
Arguments
44 - Random double
Each stream (identified by $a0 contents) is modeled by a different Random object. There are no default seed values, so use the Set Seed service (40) if replicated random sequences are desired.
Result
Arguments
50 - ConfirmDialog
Result
Arguments
51 - InputDialogInt
Result
Arguments
52 - InputDialogFloat
Result
Arguments
53 - InputDialogDouble
Result
Arguments
54 - InputDialogString
See Service 8 note below table
Result
Arguments
55 - MessageDialog
N/A
Arguments
56 - MessageDialogInt
N/A
Arguments
57 - MessageDialogFloat
N/A
Arguments
58 - MessageDialogDouble
N/A
Arguments
59 - MessageDialogString
N/A