W06_12a_ARM_Progr3

W06_12a_ARM_Progr3 - 12a ARM Programming 3 CSC 230...

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

View Full Document Right Arrow Icon
12a ARM Programming 3 CSC 230 Department of Computer Science University of Victoria 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
SHIFT OPERATIONS (conceptually) Shift Left by n bits: logical or arithmetic shift - LSL ultiplication by 2 n C 0 Multiplication by 2 Arithmetic Shift Right by n bits - ASR igned division by 2 n C Signed division by 2 Logical Shift Right by n bits - LSR Unsigned division by 2 n 2 C 0
Background image of page 2
ROTATE INSTRUCTIONS: (conceptually) Rotate Right by n bits - ROR 2 bit rotate C 32 bit rotate Rotate Right extended by one bit - RRX 33 bit rotate, 33 rd bit is carry C 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Shift and Rotate in ARM? No explicit instructions Shifts and rotate are incorporated into addressing odes modes Examples: @shift content of R2 left by 4 bits OV 2 R2 LSL #4 @ that is, R2 = R2 * 16 MOV R2,R2,LSL #4 ADD R2,R2,R1,LSL #4 @R2 = R2 + R1 * 16 @R2 = R1 / 4 MOV R2,R1,ASR #2 4 LDR R2,[ R1,R3,LSL #2] @load from address @calculated as R1 + R3 * 4
Background image of page 4
How are SHIFTS implemented in hardware for ARM? Rn Rm g Barrel shifter ocessin o pre-pr Pre-pr o esult N No Re ARITHMETIC LOGIC UNIT Rd
Background image of page 5

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

View Full DocumentRight Arrow Icon
Small Example: an ARM program for adding numbers HVZ p. 119, fig. 3.8 @ ========== Data ========== .data @ Begin the "data" segment, for variables align Next item begins at a word (aligned) .a g @ et t e b e g sa ta od( a ge d ) @ address sum: .word 0 1 word initialized to 0 n: .word 5 1 word initialized to 5 words num1: .word 3,-17,27,-12,322 uninit: .skip 4 end 5 words initialized as shown (array) .end
Background image of page 6
@ Sample ARM to add a set of numbers .text @ Begin the "text" (code) segment .global _start @ Export "_start" symbolic @ address for linker _start: ld rr 4,=n @ Load address of var 'n' ldr r1,[r4] @ Load value of 'n' ldr r2,=num1 @ Load address of num1 ov 0 #0 Initialize R0 mov r0,#0 @ Initialize R0 loop: ldr r3,[r2],#4 @ *** Note: post-indexed form @ Here R2 should have been incremented by 4 dd 0,r0,r3 update sum in r0 add r0,r0,r3 @ update sum in r0 subs r1,r1,#1 @ r1=r1-1, plus condition codes bgt loop @ Loop again if R1 > 0 @ After loop: ldr r4,=sum @ Load address of var 'sum' str r0,[r4] @ Save value of R0 into sum swi 0x11 Study by yourself
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example: Printing a 2-D array of characters .data MyArray2: .skip 25 @25 bytes for a 5x5 array of characters Rsize: .word 5 000 001 002 003 004 005 006 007 008 009 00A 00B 00C 00D 00E 00F 010 011 012 013 014 015 016 017 018 019 Csize: .word 5 C0 ABCDEFGHIJKLMNOPQRSTUVWXY r o w 0r o w 1r o w 2r o w 3r o w 4 B C DE FOR ( rr=0; rr < Rsize; rr++ ) FOR ( cc=0; cc < Csize; cc++ ) print MyArray2 [rr] [cc] AB FGH I J KLM N O PQ R ST UVW X Y
Background image of page 8
Example: Printing a 2-D array of characters C000 C001 C002 C003 C004 C005 C006 C007 C008 C009 C00 A B C C00D C00E F C010 C011 C012 C013 C014 C015 C016 C017 C018 C019 ABCDEFGHIJKLMNOPQRSTUVWXY r o w 0r o w 1r o w 2r o w 3r o w 4 R7 R4 LDR R7,=MyArray2 @ R7 has base address LDR R2,=Rsize LDR R2,[R2] @ R2 has # rows, here =5 LDR R3,=Csize LDR R3,[R3] @ R3 has # columns, here =5 mov r4,r7 @ R4 is also pointer to array base , py
Background image of page 9

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

View Full DocumentRight Arrow Icon
Example: Printing a 2-D array of characters C000 C001 C002 C003 C004 C005 C006 C007 C008 C009 C00 A B C C00D C00E F C010 C011 C012 C013 C014 C015 C016 C017 C018 C019 ABCDEFGHIJKLMNOPQRSTUVWXY r o w 0r o w 1r o w 2r o w 3r o w 4 ROWLOOP: ov 5 r3 set column counter R7 R4 R2 = 5 R3 = 5 R5 = 5 #rows #cols #cols counter mov r5,r3 @ set column counter COLLOOP: ldrb r0,[r4],#1 @ get char to be printed swi SWI_PrChr @ print it subs r5,r5,#1 @ next element, same row?
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course CSC 230 taught by Professor Jasond.corless during the Summer '11 term at University of Victoria.

Page1 / 29

W06_12a_ARM_Progr3 - 12a ARM Programming 3 CSC 230...

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

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