External Data and Text Flashcards
In the C language, local (automatic) variables are always allocated in the stack frame of a function
What is its scope and lifetime?
Scope: local to block of code where declared
Lifetime: life of the block of code
What is the scope and lifetime of static local variables?
Scope: block of code where declared
Lifetime: life of the program (persist from call to call of the function)
Stack frames can’t be stored on the stack frame for the function. Why?
Stack memory may be used by other functions
Where are static local variables stored?
In a separate section of RAM
What does the ret instruction do?
It returns from a subroutine back to the calling code
It transfers control to the address stored in the link register (x30)
It jumps to the instruction immediately following the original bl in calling code
What do the stp instructions do?
They create a frame record in each function’s stack frame
It safely stores the LR (x30), in case it is changed by a bl in the body of the function
It is restored by the ldp instruction, just before the ret
The FP and the stored FP values in the frame records form a ___________
linked list
[diagram in notes]
A called function must save/restore the state of the calling code
If it uses any of the registers __________ it must save their data to the stack at the beginning of the function
Are _________________
What must the function do in these registers just before it returns
x19-x28
callee-saved register
The function must restore the data in these registers just before it returns
Which other registers can the callee use?
x9-x15
By convention, these registers are not saved/restored by the called function
Thus .. ?
Are only safe to use in calling code between function calls
The calling code can save these registers to the stack, if it is necessary to preserve their value over a function call
Are..
Caller-saved register
How many arguments can be passed into a function using register x0 - x7?
8 or fewer
ints, short intsm and chars use w0 - w7
long ints use x0 - x7
[Example in notes]
The subroutine is free to _______ registers x0 - x7 as it executes
overwrite
The register contents are not preserved over a function call
Global Variables
Scope
Lifetime
Where they are stored
Scope: global (from declaration onwards)
Lifetime: life of program
Are stored in a separate section of RAM
[example in notes]
Static Global Variables
Scope
Lifetime
Where they are stored
Scope: local to file (from declaration onwards)
Lifetime: life of a program
Are stored in a separate section of RAM
[example in notes]