1 / 9

Understanding MIPS Program Layout: Data and Code Segments and Syscalls**

This guide explores the layout of a MIPS program, focusing on data and code segments. It explains how to define a data segment using `.data` to create strings and arrays, while the code segment is marked by `.text`. Key syscalls for input and output operations are discussed, such as printing integers, strings, and reading characters. An example demonstrates string reversal in MIPS, illustrating stack operations and syscall usage. This foundational knowledge is essential for programming in MIPS assembly language.

argyle
Download Presentation

Understanding MIPS Program Layout: Data and Code Segments and Syscalls**

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CDA 3100 Recitation Week 6

  2. Layout of MIPS program • Data segment • Specified by: .data • Code segment • Specified by: .text .globlmain main:

  3. 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

  4. 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

  5. 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

  6. 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

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

  8. 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

  9. 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

More Related