ARM Instruction

ARM goto Instruction

goto label (C) is the same as B label in ARM.

Conditional Branch

  1. Set the condition bits (N, Z, V, C) in the program status register.
  2. Then check on these condition bits to branch conditionally.

Conditional bits

N = 1 if result is Negative

Z = 1 if result is Zero

V = 1 if there’s overflow

C = 1 if there’s carry out

SUBS (with the ending S) sets conditional bits in cpsr register.

SUBS r1, r0, #0

r0 = r1 – #0, and set the condition bits NZVC based on the result.
If r1==r2, then N = 0, Z= 1, V = 0, C =1
If r < r2 (no overflow), then N =1, Z = 0, V=0

Another way to do that is to use a ‘Comparison Instruction’

CMP r1, r2
BEQ label  @if Z = 1, then go to label
COM r0, #4
BEQ this_instr
ADD r4, r5, r6
B end
this_instr: SUB r0, r0, #1
end:
if(r0 == 4)
    r0 --;
r4 = r5 + r6;
if(r0 != 4)
    r4 = r5 + r6;
r0 --;

ARM Decision Instructions

BEQ label==BRANCH EQUAL
BNE label!=BRANCH NOT EQUAL
BLE label<=BRANCH LESS THAN EQUAL
BLT label<BRANCH LESS THAN
BGE label>=BRANCH GREATER THAN EQUAL
BGT label>BRANCH GREATER THAN

The condition is T/F based upon the fields in the Program Status Register.

If…else

if (x==y)
    x += y;
else
    x -= y;
CMP r01, r1
BNE else_aprt
ADD r0, r0, r1
B end
else_part: SUB r0, r0,r1
end:
Published on October 23, 2015