-
Notifications
You must be signed in to change notification settings - Fork 137
MARS syscalls
To make simulation interactive, we use system calls in the way MARS and SPIM simulators do:
| rvice | Code in $v0 | Arguments | Result |
|---|---|---|---|
| print integer | 1 | $a0 = integer to print | |
| print float | 2 | $f12 = float to print | |
| print double | 3 | $f12 = double to print | |
| print string | 4 | $a0 = address of null-terminated string to print | |
| read integer | 5 | $v0 contains integer read | |
| read float | 6 | $f0 contains float read | |
| read double | 7 | $f0 contains double read | |
| read string | 8 | $a0 = address of input buffer | See note below table |
| $a1 = maximum number of characters to read | |||
| sbrk (allocate heap memory) |
9 | $a0 = number of bytes to allocate | $v0 contains address of allocated memory |
| exit (terminate execution) |
10 | ||
| print character | 11 | $a0 = character to print | See note below table |
| read character | 12 | $v0 contains character read | |
| open file | 13 | $a0 = address of null-terminated string containing filename | $v0 contains file descriptor (negative if error). See note below table |
| $a1 = flags | |||
| $a2 = mode | |||
| read from file | 14 | $a0 = file descriptor | $v0 contains number of characters read (0 if end-of-file, negative if error). See note below table |
| $a1 = address of input buffer | |||
| $a2 = maximum number of characters to read | |||
| write to file | 15 | $a0 = file descriptor | $v0 contains number of characters written (negative if error). See note below table |
| $a1 = address of output buffer | |||
| $a2 = number of characters to write | |||
| close file | 16 | $a0 = file descriptor | |
| exit2 (terminate with value) | 17 | $a0 = termination result | See note below table |
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.
Service 11 - Prints ASCII character corresponding to contents of low-order byte.
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. The underlying file I/O implementation uses java.io.FileInputStream.read() to read and java.io.FileOutputStream.write() to write. 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).
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,.
Service 17 - If the MIPS program is run under control of the MARS graphical interface (GUI), the exit code in $a0 is ignored.
MIPT-V / MIPT-MIPS — Cycle-accurate pre-silicon simulation.