Professional Documents
Culture Documents
1.3. Registers
The following table explains the 32 registers of MIPS for integer operations.
main:
2.2.2. Syscalls
Since you will practice MIPS assembly programming on a MIPS
simulator which runs on different processor (Intel, most probably),
running an operating system (Windows); you can neither get input
yourself from the user nor display result on screen.
Syscall is used to get the job done in this matter. Before calling syscall,
calling code should be moved to register v0. The table given below
describes the arguments required and result registers.
Syscalls are very important in QtSpim. Syscalls are used to perform
I/O operations as well as end every program. When a syscall is made,
QtSpim will check the value of register $v0 and perform a specific
function based on the given value. For example, the value 1 will print
a integer from register $a0, and the value 5 will ask for input from the
user. All input and output will be written to the console, the other
window that opened when QtSpim was opened. When the value in $v0
is 10 and a syscall is made, the program will end. Every program run
in QtSpim should finish in this way.
Getting input from user
li $v0, 5 # Call code for input is 5
syscall # make the syscall.
move $t0, $v0 # Value is read in $v0 by syscall
# Registers used:
main:
## Get first number from user, put into $t0.
li $v0, 5 # load syscall read_int into $v0.
syscall # make the syscall.
move $t0, $v0 # move the number read into $t0.
# end of add1.s.