Professional Documents
Culture Documents
Xinhui Hu
Yuan Wang
MARS
What is MARS?
MIPS simulator
# start of code
Data segment
Identify data segment and text (code) segment
.data
.word 7
.word 3
.text
.globl main
main:
System calls
syscall instruction is used for calls to the
operating systems
input
output
Basic operation
load $v0 with command to execute
put output value in $a0 (or $f12)
get input result from $v0 (or $f0)
Event
Arguments
print int
print float
print string
read int
read float
read string
exit program
print byte
$a0 = integer
$f12 = float
$a0 = pointer to string
Result
Printing an integer
Command is 1
Command must be in register
Value to print must be in register a0
Example: print the value 10
addi $v0, $v0, 1 # command to print integer
addi $a0, $a0, 10 # value to print
syscall
Printing a string
Command is 4
$v0 must hold command
$a0 must hold address of string to print
Example: print hello
li
$v0, 4
la
$a0, hello
syscall
Reading input
Command is 5
$v0 must hold command
$v0 get result
Example: read number
li
$v0, 5
syscall
move $t0, $v0