Subroutines Flashcards

1
Q

instruction used to call subroutines

A

BL subroutineName

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

what does BL stand for

A

branch and link

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

what does BL do

A

it remembers the address of the instruction immediatelt following the branch and link

it acts as a normal branch instruction

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

within subroutine, how to branch back to main/where you were before

A

BX LR

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

at the beginning of a subroutine, you should always push….

A

LR and any registers used by the subroutine

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

at the end of a subroutine, you should always pop

A

PC and any registers used by the subroutine

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

why do we push an pop any registers used as local variables within the subroutine

A

to hide the fact that they were used within the subroutine

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

what should be included in interface specification commments

A
  1. name of subroutine
  2. description of subroutine
  3. what parameters will be passed
  4. what it returns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does AAPCS stand for

A

ARM architecture procedure call standards

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

according to AAPCS what registers should be used for passing parameters in subroutines

A

R0-R3

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

according to AAPCS what registers should be used for local variables in subroutines

A

R4-R12

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

in what register is the link register

A

r14

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

in what register is the program counter

A

r15

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

when popping at the end of the subroutine, why do we pop right into the PC

A

itll go right to that address after the pop instruction

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

through what registers should values be returned

A

r0

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

what is good practice to do with parameters at the start of the subroutine

A

pass them into local variable registers

17
Q

how to pass parameters using the stacl

A

push parameters on one by one, order is important

subroutine pops them off at beginnig

18
Q

why might you want to pass parameters using the stack

A

not enough in r0-r3

19
Q

which register is the scratch register

A

r12

20
Q

what is the scratch register

A

skips over the other elements saved on the stack to get to the location the parameters passed start at

21
Q

how to access scratch register

A

ADD R12, SP, #(number of parameters passed using the system stack)*4