Assembler Directives
description
Transcript of Assembler Directives
![Page 1: Assembler Directives](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da8080f/html5/thumbnails/1.jpg)
Assembler Directives
Example program:
.data # DATA segmentcity: .asciiz “Seattle”
.align 2num: .word 2210, 2341, 26, 0x022ec, 0x11110087
.byte 65, 79, 253
.text # CODE segment
.globl main # declaring “main” as global
main: li $v0, 4 # syscall for print_stringla $a0, city # argument in $a0syscall
la $t0, num # get address of first number
lw $s0, 0($t0) # s0 = 2210 lw $s1, 4($t0) # s1 = 2341
add $s0, $s0, $s1 # s0 = 2210+2341li $v0, 1 # syscall for print_intmove $a0, $s0 # argument in $a0syscall
.end main
![Page 2: Assembler Directives](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da8080f/html5/thumbnails/2.jpg)
General format of MIPS programs
Xspim on our machines automatically loads some assembly code that takes care of calling “main”
Need to write code that looks roughly like the following:
.data # DATA segment
lab1: .byte ……… lab2: .asciiz …… # some static data
.float ………lab3: .double ……...
.text # CODE segment
.globl main # declaring “main” as global
main: <your part of the code>…...
.end main
![Page 3: Assembler Directives](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da8080f/html5/thumbnails/3.jpg)
If-then-else in MIPS
What does the following C code looks like in MIPS assembly language:
if (a < b) { a = a + 1; b = b - 1;}else { a = a * 2; b = b / 2;}
Assume $s0 contains a, and $s1 contains b.
![Page 4: Assembler Directives](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da8080f/html5/thumbnails/4.jpg)
If-then-else (cont.)
# if (a < b)slt $t0, $s0, $s1beq $t0, $zero, else_label
# a = a + 1, b = b - 1addi $s0, $s0, 1subi $s1, $s1, 1j end_label
# else a = a * 2, b = b / 2else_label:sll $s0, $s0, 1sra $s1, $s1, 1
# end of if-then-elseend:<statements following if-then-else>
![Page 5: Assembler Directives](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da8080f/html5/thumbnails/5.jpg)
From C Program to Machine Language
Stages in the transformation:
C program
Assembly Language program
Object : MachineLanguage Module
Library routinesMachine Lang
Executable (Machine Language)
Memory
Compiler
Assembler
Linker
Loader