Subroutines Flashcards
instruction used to call subroutines
BL subroutineName
what does BL stand for
branch and link
what does BL do
it remembers the address of the instruction immediatelt following the branch and link
it acts as a normal branch instruction
within subroutine, how to branch back to main/where you were before
BX LR
at the beginning of a subroutine, you should always push….
LR and any registers used by the subroutine
at the end of a subroutine, you should always pop
PC and any registers used by the subroutine
why do we push an pop any registers used as local variables within the subroutine
to hide the fact that they were used within the subroutine
what should be included in interface specification commments
- name of subroutine
- description of subroutine
- what parameters will be passed
- what it returns
what does AAPCS stand for
ARM architecture procedure call standards
according to AAPCS what registers should be used for passing parameters in subroutines
R0-R3
according to AAPCS what registers should be used for local variables in subroutines
R4-R12
in what register is the link register
r14
in what register is the program counter
r15
when popping at the end of the subroutine, why do we pop right into the PC
itll go right to that address after the pop instruction
through what registers should values be returned
r0
what is good practice to do with parameters at the start of the subroutine
pass them into local variable registers
how to pass parameters using the stacl
push parameters on one by one, order is important
subroutine pops them off at beginnig
why might you want to pass parameters using the stack
not enough in r0-r3
which register is the scratch register
r12
what is the scratch register
skips over the other elements saved on the stack to get to the location the parameters passed start at
how to access scratch register
ADD R12, SP, #(number of parameters passed using the system stack)*4