Upload
radians042
View
215
Download
0
Embed Size (px)
DESCRIPTION
g
Citation preview
Syscall in MIPSXinhui HuYuan Wang
MARSWhat is MARS?MIPS simulatorHow to get it?http://courses.missouristate.edu/KenVollmar/Mars/download.htmJava basedHow to use it?Use the tutorial in the websiteAssemble->execute->step-by-step execute
Every line contains at most one instruction# marks beginning of commentassembly language program require more comments!at least one per line!
Format of a MIPS program
Identify data segment and text (code) segment
.data.text.globl mainmain:# start of code
On simulator, data segment starts at 0x10010000Parts of a MIPS program
Identify data segment and text (code) segment
.data.word 7#one word with initial value 7.word 3#one word with initial value 3.text.globl mainmain:# start of code
On simulator, data segment starts at 0x10010000Data segment
Locations in data section can be marked with labelLabel represents the address of where the data is in memory
.datafirst: .word 7#one word with initial value 7last: .word 3#one word with initial value 3
Data and labels
System callssyscall instruction is used for calls to the operating systemsinputoutputBasic operationload $v0 with command to executeput output value in $a0 (or $f12)get input result from $v0 (or $f0)
Command Event Arguments Result (in $v0)
1 print int $a0 = integer $a0 is printed out 2 print float $f12 = float $f12 is printed out 4 print string $a0 = pointer to string string is printed out 5 read int $v0 holds integer read 6 read float $f0 holds float read 8 read string $a0 = buffer,a1 = length string is read from console 10 exit program 11 print byte $a0 = byte byte is printed out
Useful syscall Commands
Command is 1Command must be in registerValue to print must be in register a0
Example: print the value 10
addi$v0, $v0, 1 # command to print integeraddi$a0, $a0, 10 # value to printsyscall
Printing an integer
Strings for outputDefine in data section of programUse labels to identify different stringsLabels represent addresses in memoryStrings are C strings (end with 0)
.dataprompt: .asciiz "Enter in an integer: "str1: .asciiz "The integer is: "newline: .asciiz "\n " hello: .asciizHello, students of CSE230!
Printing a stringCommand is 4$v0 must hold command$a0 must hold address of string to print
Example: print hello
li$v0, 4#command to print stringla$a0, hello# load address of stringsyscall
Reading inputCommand is 5$v0 must hold command$v0 get result
Example: read number
li$v0, 5# command to read integersyscallmove$t0, $v0# result saved in $t0
**********