W05_11_ARM_Progr2 - 11 ARM Programming 2 CSC 230 Department...

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

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

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

View Full DocumentRight Arrow Icon
Control Structures ± IF … THEN F THEN ELSE ± IF … THEN … ELSE ± WHILE … DO ± FOR … ± DO … WHILE (a.k.a. REPEAT)
Background image of page 2
Control Structures: IF … THEN if TRUE then execute: Is <condition> True? Code (T); Code (S); TRUE FALSE if FALSE then execute: Code (S) only; Code (T); Code (S);
Background image of page 3

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

View Full DocumentRight Arrow Icon
IF (X = = Y) { Z = X + Z;} /*CodeT*/ K = Z –T; /*CodeS*/ Is <condition> rue? ; / / CMP X,Y BEQ CodeT AL odeS True? ALSE TRUE if X==Y BAL CodeS CodeT: ADD R3,R1,R3 CodeS: SUB R4,R3,R5 Code (S); FALSE Code (T); if X != Y IF (X != Y) { GO TO L } break Is ELSE Z = X + Z; /*CodeT*/ L: K = Z – T; /*CodeS*/ MP Y ALSE NOT <condition> True? CMP X,Y BNE CodeS CodeT: ADD R3,R1,R3 FALSE TRUE Code (T); CodeS: SUB R4,R3,R5 Code (S);
Background image of page 4
Control Structures: IF … THEN … ELSE Is <condition> if TRUE then execute: Code (T); Code (Z); FALSE TRUE True? ELSE then execute: Code (S); ode (S); ode (T); Code (Z); Code (S); Code (T); Code (Z);
Background image of page 5

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

View Full DocumentRight Arrow Icon
if (x > 0) { 1 = x – ; LDR r1,=x @r1 = address of x DR 2 [r1] 2=x T1 x 2; } else { LDR r2,[r1] @ r2 = x CMP r2,#0 @ compare x to 0 GT 1updt f x>0, goto T1updt S2 = x + 3; } BGT T1updt @ if x>0, goto T1updt S2updt: LDR r4,=S2 @ r4 = address of S2 ADD r5,r2,#3 @ r5 = S2 = x+3 sum=Y+Z; STR r5,[r4] @ store S2 BAL ContSum T1updt: LDR r3,=T1 @ r3=address of T1 SUB r6,r2,#2 @ r6 = T1 = x-2 STR r6,[r3] @ store T1 ontS m ContSum: LDR r1,=sum @ r1 = address of sum etc. etc. 1 dt 2 dt When T1updt is finished, continue directly with code from ContSum When S2updt is finished, need a BAL (a GOTO) to ContSum to skip T1updt
Background image of page 6
Test yourself Do by ourself R1 = 0x0000 00FF R2 = 0x00000000 CMP R1,R2 yourself Which conditional instruction will cause a branch? BEQ Equal (zero) Z=1 BNE Not equal (zero) Z=0 BMI Minus (negative) N=1 BPL Plus (positive or zero) N=0 VS verflow =1 BVS Overflow V=1 BHI Unsigned higher BLS Unsigned lower or same 0 CZ ∨= 1 BGE Signed greater or equal BLT Signed less BGT Signed greater 0 NV = 1 = ( ) 0 ZN V ∨⊕ = BLE Signed less BAL Always ( ) 1 V =
Background image of page 7

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

View Full DocumentRight Arrow Icon
Control Structures: loops, choices, details ± conditional or counted ± test at beginning or at end of loop ± increment at beginning or end of loop ± avoid random placement of loop elements e careful with nested loops ± be careful with nested loops ± watch for register conflicts ll ontrol and data structures must be All control and data structures must be implemented by the programmer using low-level primitives (i.e. Branch instructions) Great care and discipline is required The main job of a compiler is to translate high-level concepts/control structures to very efficient low- level machine instructions
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 28

W05_11_ARM_Progr2 - 11 ARM Programming 2 CSC 230 Department...

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

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