Parameters are used to tell the O/S what function syscall is to perform. The system procedures use register $2 ($v0) to specify the type code for the function. Additional parameters are passed in registers $a0-$a3 and $f12. System procedures which return values use $v0 and $f0 for floating point results.
The type codes and parameters are system dependent. In the SPIM simulator, the following system procedures are defined.
To perform the MAL puti function, register $v0 is loaded with type code 1 and the integer to be printed is placed in $a0: The MAL instruction:
puti $12
would be synthesized in TAL as:
addi $v0, $0, 1 # type code = puti
add $a0, $12, $0 # move $4, $12
syscall # call system procedure
The MAL instruction:
geti $12
would be synthesized in TAL as:
addi $v0, $0, 5 # type code = geti
syscall # call system procedure
add $12, $v0, $0 # move result to $12
To print or read a string, the address of the string is passed as a parameter. The following MAL code uses puts to print "Hello World":
.data
Hello: .asciiz "Hello World\n"
.text
puts Hello
The puts instruction is implemented using syscall as:
addi $v0, $0, 4 # type code = puts
la $a0, Hello # address of string
syscall # call system procedure
The MAL done macro is also implemented as a system procedure as follows:
addi $v0, $0, 10 # type code = done
syscall # call system procedure
Note that the use of $v0 for the type code precludes the use of $v0 ($2) in any MAL I/O instruction. For example,
puti $2
will always print the value 1, which is the type code for the puti instruction.
Refer to the SPIM Simulator Reference Manual for additional information on the use of system procedures.