assembly - CSE 341 MIPS Assembly Language Assembly Language...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 341 MIPS Assembly Language Assembly Language Machine Language Assembly Language Symbolic representation of machine language Mnemonics represent opcodes Labels represent memory locations Comparing Assembly Language to Machine Language C Program int main() { int temp[10]; int i, sum, min, max; sum=0; min=temp[0]; max=temp[0]; for (i=0; i<10; i++) { if (temp[i] < min) {min = temp[i];}; if (temp[i] > max) {max = temp[i];}; sum = temp[i] + sum; } } ARM Assembly Language sub r13,r13,#0x28 ldr r2,[r13,#0] ldr r3,[r13,#0] mov r0,#0 ldr r1,[r13,r0,lsl #2] cmp r1,r2 bge 0x80c8 ; (main + 0x20) mov r2,r1 cmp r1,r3 ble 0x80d4 ; (main + 0x2c) mov r3,r1 add r0,r0,#1 cmp r0,#0xa blt 0x80b8 ; (main + 0x10) mov r0,#0 add r13,r13,#0x28
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ARM Machine Language 11100010010011011101000000101000 11100101100111010010000000000000 11100101100111010011000000000000 11100011101000000000000000000000 11100111100111010001000100000000 11100001010100010000000000000010 10101010000000000000000000000000 11100001101000000010000000000001 11100001010100010000000000000011 11011010000000000000000000000000 11100001101000000011000000000001 11100010100000000000000000000001 11100011010100000000000000001010 10111010111111111111111111110101 11100011101000000000000000000000 The Big Picture Example Consider the high level language line of code y:=9 * x + 17 - z; Steps Load x Load z Store result temporarily Store result temporarily Subtract z from temporary result Store computation in memory location y Program Compiler Assembly Language Program High-Level Language Program Assembler Linker Computer Figure B.1.6 (page B-8) from David A. Patterson and John L. Hennessy , Computer Organization and Design, The Hardware/Software Interface , 4 th Edition, Elsevier, 2009
Background image of page 2
Assembly .globl main .data x: .byte 25 y: .byte 7 z: .byte 9 .text main: lui $t0, 0x1000 lb $t1, 0($t0) # Load x lb $t2, 2($t0) # Load z sll $t3, $t1, 3 # Calculate x * 9 add $t3, $t3, $t1 addi $t1, $t3, 17 # Add 17 to product of x*9 sub $t1, $t1, $t2 # Subtract z from x*9+17 sb $t1, 1($t0) # Store result (y) Example Consider a loop, such as a FOR loop in a high level language for (i=0; i<12; i++) sum:=array[i]; Steps Initialization: Initialize running sum (with array[0]) Initialize counter (i) Loop: Load element (array[i]) Calculate running sum Increment count Done? If not, repeat loop Assembly .globl main .globl calc_sum .data array: .byte 3 .byte 20 .byte 17 .byte 5 .byte 2 .byte 91 .byte 7 .byte 31 .byte 5 .byte 4 .byte 50 .byte 63
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
.text main: lui $t0, 0x1000 # Initialize pointer lb $v0, 0($t0) # Load running sum with array[0] add $t2, $0, $0 # Initialize counter addi $t0, $t0, 1 # Initialize pointer calc_sum: lb $t1, 0($t0) # Load array[i] add $v0, $v0, $t1 # Running sum addi $t2, $t2, 1 # Increment count slt $t3, $t2, 12 bne $t3, $0, calc_sum # Repeat? addi $t0, $t0, 1
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

assembly - CSE 341 MIPS Assembly Language Assembly Language...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online