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

Info icon This preview shows pages 1–10. 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
Image of page 1

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

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

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

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

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

View Full Document Right Arrow Icon
if (x > 0) { T1 = x – 2; LDR r1,=x @r1 = address of x LDR r2 [r1] @ r2 = x T1 x 2; } else { r2,[r1] CMP r2,#0 @ compare x to 0 BGT T1updt @ if x>0, goto T1updt S2 = x + 3; } 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 ContS m ContSum: LDR r1,=sum @ r1 = address of sum etc. etc. Wh T1 dt i fi i h d Wh S2 dt i fi i h d When T1updt is finished, continue directly with code from ContSum When S2updt is finished, need a BAL (a GOTO) to ContSum to skip T1updt
Image of page 6
Test yourself Do by yourself R1 = 0x0000 00FF R2 = 0x00000000 CMP R1,R2 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 BVS Overflow V=1 BHI Unsigned higher BLS Unsigned lower or same BGE Si d l 0 C Z = 1 C Z = 0 N V Signed greater or equal BLT Signed less BGT Signed greater = 1 N V = ( ) 0 Z N V = BLE Signed less BAL Always ( ) 1 Z N V =
Image of page 7

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

View Full Document Right 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 be careful with nested loops watch for register conflicts 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
Image of page 8
Control Structures: WHILE … DO while (p !=q ) { Code (S); WHILE C is true { DO S } true Modify condition; }
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern