Presentation is loading. Please wait.

Presentation is loading. Please wait.

Syscall in MIPS Xinhui Hu Yuan Wang. MARS What is MARS? – MIPS simulator How to get it? – s/download.htm.

Similar presentations


Presentation on theme: "Syscall in MIPS Xinhui Hu Yuan Wang. MARS What is MARS? – MIPS simulator How to get it? – s/download.htm."— Presentation transcript:

1 Syscall in MIPS Xinhui Hu Yuan Wang

2 MARS What is MARS? – MIPS simulator How to get it? – s/download.htm s/download.htm – Java based How to use it? – Use the tutorial in the website – Assemble->execute->step-by-step execute

3 Every line contains at most one instruction # marks beginning of comment – assembly language program require more comments! – at least one per line! Format of a MIPS program

4 Identify data segment and text (code) segment.data.text.globl main main:# start of code On simulator, data segment starts at 0x Parts of a MIPS program

5 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 main main:# start of code On simulator, data segment starts at 0x Data segment

6 Locations in data section can be marked with label Label represents the address of where the data is in memory.data first:.word 7#one word with initial value 7 last:.word 3#one word with initial value 3 Data and labels

7 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)

8 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

9 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 an integer

10 Strings for output Define in data section of program Use labels to identify different strings – Labels represent addresses in memory Strings are C strings (end with 0).data prompt:.asciiz "Enter in an integer: " str1:.asciiz "The integer is: " newline:.asciiz "\n " hello:.asciiz”Hello, students of CSE230!”

11 Printing a string Command is 4 $v0 must hold command $a0 must hold address of string to print Example: print hello li$v0, 4#command to print string la$a0, hello# load address of string syscall

12 Reading input Command is 5 $v0 must hold command $v0 get result Example: read number li$v0, 5# command to read integer syscall move$t0, $v0# result saved in $t0


Download ppt "Syscall in MIPS Xinhui Hu Yuan Wang. MARS What is MARS? – MIPS simulator How to get it? – s/download.htm."

Similar presentations


Ads by Google