A system call (syscall) in MIPS assembly is a way for a program to request a service from the operating system.
The syscall instruction is used, with the type of call specified in the $v0 register. Arguments for the syscall are placed in registers $a0, $a1, $a2, and $a3 as needed. Results are usually returned in $v0 and sometimes $v1.
We can categorize the system calls (syscalls) in MIPS assembly in 3 category:
Print Syscalls: These syscalls are used to output data. They can print different types of data including integers, floating-point numbers, and strings. The data to be printed is typically passed in a specific register (like $a0 or $f12).
Read Syscalls: These syscalls are used to read input data from the user. They can read different types of data including integers, floating-point numbers, and strings. The read data is typically returned in a specific register (like $v0 or $f0), or stored in a buffer whose address is passed in a specific register (like $a0).
Exit Syscall: This syscall is used to terminate the program. It doesn’t require any arguments and doesn’t return any result.
Note
Remember, these are just some of the basic syscalls. MIPS provides many other syscalls for various purposes, such as file I/O, memory allocation, and process control.
Print Syscalls
Print syscalls are used to output data. They can print different types of data including integers, floating-point numbers, and strings. The data to be printed is typically passed in a specific register (like $a0 or $f12).
Print integer
li $v0, 1move $a0, $t0 # Assume $t0 contains the integer to printsyscall
Print float
li $v0, 2l.s $f12, float_value # Assume float_value is a .float directivesyscall
Print string
li $v0, 4la $a0, string # Assume string is a null-terminated stringsyscall
Read Syscalls
Read syscalls are used to read input data from the user. They can read different types of data including integers, floating-point numbers, and strings. The read data is typically returned in a specific register (like $v0 or $f0), or stored in a buffer whose address is passed in a specific register (like $a0).
Read integer
li $v0, 5syscallmove $t0, $v0 # $t0 now contains the read integer
Read float
li $v0, 6syscallmov.s $f12, $f0 # $f12 now contains the read float
Read string
li $v0, 8la $a0, buffer # Assume buffer is a .space directiveli $a1, 100 # Read up to 100 characterssyscall
Exit Syscall
The exit syscall is used to terminate the program. It doesn’t require any arguments and doesn’t return any result.