SlideServe
Menu
Préférences
© SlideServe · v2026

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

argyle avatar
9 diapositives · 222 Views · Sep 11, 2014

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.

Understanding MIPS Program Layout: Data and Code Segments and Syscalls** - slide 1
01 / 9Understanding MIPS Program Layout: Data and Code Segments and Syscalls**
1 / 17

Télécharger la présentation

Understanding MIPS Program Layout: Data and Code Segments and Syscalls**
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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