Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,

Similar presentations


Presentation on theme: "Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,"— Presentation transcript:

1 Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word , 2341, 26, 0x022ec, 0x byte 65, 79, text # CODE segment .globl main # declaring “main” as global main: li $v0, # syscall for print_string la $a0, city # argument in $a0 syscall la $t0, num # get address of first number lw $s0, 0($t0) # s0 = lw $s1, 4($t0) # s1 = add $s0, $s0, $s1 # s0 = li $v0, # syscall for print_int move $a0, $s # argument in $a0 syscall .end main

2 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

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

4 If-then-else (cont.) # if (a < b) slt $t0, $s0, $s1 beq $t0, $zero, else_label # a = a + 1, b = b - 1 addi $s0, $s0, 1 subi $s1, $s1, 1 j end_label # else a = a * 2, b = b / 2 else_label: sll $s0, $s0, 1 sra $s1, $s1, 1 # end of if-then-else end: <statements following if-then-else>

5 From C Program to Machine Language
Stages in the transformation: C program Compiler Assembly Language program Assembler Object : Machine Language Module Library routines Machine Lang Linker Executable (Machine Language) Loader Memory


Download ppt "Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,"

Similar presentations


Ads by Google