1/18
Flashcards about functions and procedures in assembly language, including function structure, register usage, stack operations, and calling conventions.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the benefits of using functions in programming?
Functions can greatly simplify programming tasks by providing abstraction, modularity, code reuse, readability, testability & validation, and maintainability.
What is a function?
A function is a stored subroutine that performs a specific task based on the parameters with which it is provided.
Why are procedures used in programming?
Complex operations can be performed by calling a procedure, making code easier to understand, manage, and reuse.
Is branching to a label considered a function?
Branching to a label is not a function; specific rules must be followed to implement a function.
Describe functions in terms of carrying out a mission.
Functions are assigned a secret mission, acquire necessary resources, perform the mission, leave no trace, and return safely to the point of origin.
What are the steps in function execution?
Caller stores arguments, transfers flow control to the callee, callee allocates memory, executes the function body, stores the result, deallocates memory, and returns control to the caller.
How do you perform a procedure call and return in assembly?
bl (branch and link) stores the address of the next instruction in the link register (lr) and then jumps to the ProcedureAddress; to return, mov pc, lr is used.
What are the registers used for procedure calls?
r0-r3 are argument registers, r0 is the return value register, and lr is the return address register.
What is stack memory?
Stack is a memory region used to store local state for functions, it is a dynamic memory region, and follows a LIFO structure.
What is the stack pointer?
The stack pointer (sp) starts at address 0x20020000 and is used to grow (decrease sp) and shrink (increase sp) the stack.
What is stored in the stack?
The stack is used to store preserved registers, local function variables, and input arguments to the function.
What are the different types of registers according to the assembly convention?
r4-r11 are saved registers, r12 is a temporary register, SP (r13) is the stack pointer, r0-r3 are argument registers, and LR (r14) is the return address register.
What is register spilling?
Moving the contents of registers to the main memory is called spilling registers.
How does the ARM stack grow?
The stack pointer (SP) points to the top of the stack, and the ARM stack grows down in memory.
What are the functions of push and pop instructions for the stack?
Push modifies sp to make space and saves registers in memory; pop restores sp and registers.
What are leaf procedures?
Leaf procedures are procedures that don’t call other procedures.
What is the effect of the instruction push {r4, r5, lr}
?
The instruction push {r4, r5, lr}
saves the contents of r4, r5, and lr onto the stack, decrementing the stack pointer.
What is the effect of the instruction pop {r4, r5, lr}
?
The instruction pop {r4, r5, lr}
restores the contents of r4, r5, and lr from the stack, incrementing the stack pointer.
Give examples of non-preserved registers
Examples of non-preserved registers include r0, r1, r2 and r3