System Calls


The instruction syscall is used to read or print values or strings from input/output window, and indicate program end. In order to use it,
  1. First supply appropriate values in registers $v0 and $a0-$a1.
  2. Result value (if any) is returned in register $v0.
The following table lists the possible 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