Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

INTRODUCTION TO ARM 1

PREDICATED EXECUTION AND INDIRECT BRANCHES

Conditional Execution

• Also known as “predicated execution”


• ARM allows every instruction to be “conditional”
• Why use “conditional execution”? Branches can
lower performance (as we will see later).

SECTION 15: CONDITIONAL EXECUTION, AND


INTRODUCTION TO ARM
INDIRECT BRANCHES 2
Example

Convert following ARM assembly code to use


conditional execution:

CMP R3,R4
BNE Else // goto Else if i != j
ADD r0,r1,r2 // f = g + h (skipped if i ≠ j)
B Exit // go to Exit
Else: SUB r0,r1,r2 // f = g – h (skipped if i = j)
Exit:

SECTION 15: CONDITIONAL EXECUTION, AND


INTRODUCTION TO ARM
INDIRECT BRANCHES 3
Solution

Eliminate branches by adding opposite condition


to one which causes instruction to be skipped:

CMP R3,R4
BNE Else // goto Else if i != j
ADD r0,r1,r2 // f = g + h (skipped if i ≠ j)
B Exit // go to Exit
Else: SUB r0,r1,r2 // f = g – h (skipped if i = j)
Exit:

CMP R3,R4
ADDEQ r0,r1,r2 // f = g + h (skipped if i ≠ j)
SUBNE r0,r1,r2 // f = g – h (skipped if i = j)

SECTION 15: CONDITIONAL EXECUTION, AND


INTRODUCTION TO ARM
INDIRECT BRANCHES 4
Indirect Branches

Address of next instruction can be specified in a


register

BX Rm

MOV PC, Rm

SECTION 15: CONDITIONAL EXECUTION, AND


INTRODUCTION TO ARM
INDIRECT BRANCHES 5

You might also like