syscall is used to read or print values or strings from input/output window, and indicate program end.
In order to use it,
$v0 and $a0-$a1.
$v0.
syscall services and some of the services are explained next.
MARS provides extended syscall services here and you may use them in your programming exercises.
| Service | Code in $v0 |
Arguments | Result |
|---|---|---|---|
| print_int | 1 | $a0 = integer to be printed |
|
| print_float | 2 | $f12 = float to be printed |
|
| print_double | 3 | $f12 = double to be printed |
|
| print_string | 4 | $a0 = address of string in memory |
|
| read_int | 5 | integer returned in $v0 |
|
| read_float | 6 | float returned in $v0 |
|
| read_double | 7 | double returned in $v0 |
|
| read_string | 8 | $a0 = address of string input buffer$a1 = length of string buffer (n) |
|
| malloc | 9 | $a0 = amount |
address in $v0 |
| exit | 10 | ||
| print character | 11 | $a0 = character to be printed |
|
| read character | 12 | character returned in $v0 |
.asciiz creates a null-terminated character string.
For example, the following code prints out a string:
.data
string: .asciiz "Print this.\n"
.text
main: li $v0, 4
la $a0, string
syscall
where li is load immediate value and la is load address.
|
I just got my doctor’s test results and I’m really upset. Turns out, I’m not gonna be a doctor. |