Contol Flow Instructions
Contol Flow Instructions
N Z C V Q JU n d e f i n e d I F T mode
f s x c
cpsr
spsr
spsr spsr spsr spsr spsr spsr
Compiling C if into ARM
Final
compiled MIPS code:
Loop SUB r1,r1,#1 ; g--
ADD r3,r3,r4 ; i=i+j
CMP r3,r2 ; cmp i,h
BNE Loop ; goto Loop
; if i!=h
Inequalities in ARM
Until now, we‟ve only tested equalities
(== and != in C). General programs need to test < and
> as well.
Use CMP and BLE, BLT, BGE, BGT
Examples:
if (f < 10) goto Loop; => CMP r0,#10
BLT Loop
if (f >= i) goto Loop; => CMP r0,r3
BGE Loop
Loops in C/Assembly
There are three types of loops in C:
while
do… while
for
5 instructions 3 instructions
5 words 3 words
5 or 6 cycles 3 cycles
Conclusions
A Decision allows us to decide which pieces of code to
execute at run-time rather than at compile-time.
C Decisions are made using conditional statements
within an if, while, do while or for.
CMP instruction sets status register bits
ARM Decision making instructions are the conditional
branches: BNE,BEQ,BLE,BLT,BGE,BGT.
Conclusion
Instructions so far:
Previously:
ADD, SUB, MUL, MULA, [U|S]MULL, [U|S]MLAL, RSB
AND, ORR, EOR, BIC
MOV, MVN
LSL, LSR, ASR, ROR
New:
CMP, B{EQ,NE,LT,LE,GT,GE}