Branch Instructions Flashcards

1
Q

how do we implement control structures like for and while loops?

A

Branch instructions are used to alter control flow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • BBranch
    • ?
  • BLBranch with Link
    • ?
A
  • BBranch
    • PC := <address></address>
  • BLBranch with Link
    • R14 := address of next instruction, PC := <address></address>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we return from the subroutine which BL invoked?

A

MOV pc, r14

or

BX r14 (on ARMv4T or later)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the following code do?

... ; some code here B fwd ; jump to label 'fwd' ... ; more code here fwd
A

Branching forward, to skip over some code:

... ; some code here B fwd ; jump to label 'fwd' ... ; more code here fwd
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does this code do?

back ... ; more code here B back ; jump to label 'back'
A

Branching backwards, creating a loop:

back ... ; more code here B back ; jump to label 'back'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does this code do?

... ... BL calc ; call 'calc' ... ; returns to here ... calc ; function body ADD r0, r1, r2 ; do some work here MOV pc, r14 ; PC = R14 to return
A

Using BL to call a subroutine:

... ... BL calc ; call 'calc' ... ; returns to here ... calc ; function body ADD r0, r1, r2 ; do some work here MOV pc, r14 ; PC = R14 to return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Are Branches PC-relative?

A

Branches are PC-relative. +/-32M range (24 bits × 4 bytes).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ARM’s branch instructions are PC-______ the code produced is position ___________ — it can execute from any address in memory. Certain systems such as BREW use this.

A

ARM’s branch instructions are PC-relative the code produced is position independent — it can execute from any address in memory. Certain systems such as BREW use this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we perform longer branches which access the full 32-bit address space?

A

You can set up the LR manually if needed, then load into PC:

MOV lr,pc LDR pc,=dest
How well did you know this?
1
Not at all
2
3
4
5
Perfectly