Cda 3100
Download
1 / 9

CDA 3100 - PowerPoint PPT Presentation


  • 90 Views
  • Uploaded on

CDA 3100. Recitation Week 6. Layout of MIPS program. Data segment Specified by: .data Code segment Specified by: .text . globl main main:. Data Segment Examples. Create strings of text msg : . asciiz “hello world” Create arrays of data A: .word 0,1,2,3,4,5,6,7,8,9

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CDA 3100' - argyle


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Cda 3100

CDA 3100

Recitation Week 6


Layout of mips program
Layout of MIPS program

  • Data segment

    • Specified by:

      .data

  • Code segment

    • Specified by:

      .text

      .globlmain

      main:


Data segment examples
Data Segment Examples

  • Create strings of text

    msg: .asciiz “hello world”

  • Create arrays of data

    A: .word 0,1,2,3,4,5,6,7,8,9

  • Allocate a chunk of memory

    empty: .space 400


Syscalls
Syscalls

  • Performs a variable service dependent upon the values in various registers

  • $v0 specifies the operation

  • $a0 (typically) specifies the argument

    • Other places arguments can come from:

      • $a1, $a2, $a3 – for operations with multiple args

      • $f12 – for floating point number calls

  • Sample call:

    li $v0, 1

    li $a0, 20

    syscall


Common syscalls examples
Common Syscalls Examples

  • Print integer

    • $v0 = 1, $a0 = integer to print

  • Print float

    • $v0 = 2, $f12 = float to print

  • Print string

    • $v0 = 4, $a0 = string_address

  • Print character

    • $v0 = 11, $a0 = character to print

  • Read integer

    • $v0 = 5; after call, $v0 = integer read

  • Read character

    • $v0 = 12; after call, $v0 = character read

  • Quit execution

    • $v0 = 10

  • More examples:

    • http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html


Reverse a string part 1
Reverse a String (Part 1)

.data

msg: .asciiz "hello world“

endl: .asciiz "\n"

.text

.globl main

main: # Initialize stack and load ‘msg’

addi$sp,$sp,-1

sb$0,0($sp)

la $t1, msg


Reverse a string part 2
Reverse a String (Part 2)

L0: # Load ‘msg’ string onto stack

lb$t0,0($t1)

beq$t0,$0, L1

addi$sp,$sp,-1

sb$t0,0($sp)

addi$t1,$t1,1

j L0

L1: # Reload ‘msg’ pointer

la $t1,msg


Reverse a string part 3
Reverse a String (Part 3)

L2: # Replace string at ‘msg’

lb$t0,0($sp)

addi$sp,$sp,1

sb$t0,0($t1)

beq$t0, $0, L3

addi$t1,$t1,1

j L2


Reverse a string part 4
Reverse a String (Part 4)

L3: # Print messages and quit

la $a0,msg # Load string located at ‘msg’

li $v0,4

syscall

la $a0,endl # Load string located at ‘endl’

li $v0,4

syscall

li $v0,10 # Exit

syscall


ad