External Data & Text Flashcards
In C, where are local (automatic) variables allocated?
What is their scope?
What is their lifetime?
In the stack frame
The block of code where declared
The life of the block of code
Where are static local variables stored?
What is the scope?
What is the lifetime?
Not in stack because it is designed to store things with a short lifetime. In a separate location of RAM
Block of code where declared
Life of program (persist from call to call of the function
Where are global variables stored?
What is the scope?
What is the lifetime?
In a separate section of RAM
Global (even throughout files)
Life of program
Where are static local variables stored?
What is the scope?
What is the lifetime?
In a separate location in RAM
Local to file from declaration point onwards
Lifetime: life of program
What are the 3 sections of memory that programs may allocate?
.text
.data
.bss
What does the text section contain?
Program text (machine code)
Read-only, programmer-initialized data
What will happen if you try to write to text memory?
A segmentation fault will occur because text is read-only mem
What does the data section contain?
Programmer-initialized data
Is read/write memory
What does bss stand for and what does it have?
Block Starting Symbol
Reserved for zero-initialized data
Where are the text, data and bss sections stored?
In low memory, just after the OS kernel section (see diagram)
How do you indicate that what follows goes into a particular section?
Use pseudo-ops
.text (default section when assembling)
.data
.bss
The assembler uses a _____ counter for each section (like text, data, bss)
Location counter
What does the location counter do?
- starts at 0 and increases as instructions and data are processed
- final step of assembly gathers all code and data into appropriate sections
What is the order of sections loaded when the OS loads a program into RAM?
- text & data
- bss section is zeroed
External variables: low or high level concept?
low
What are external variables and where are they allocated?
Non-local variables used to implement C language global & static variables. Allocated in the data or bss sections
What pseudo-ops can be used to allocate & initialize external variables? What is the general form for allocating& initializing EVs?
.byte, .hword, .word, .dword
check notes
What do the labels of external variables represent?
64-bit addresses
External variables: how to put the address in a register and how to access one
Use adrp & add to put the address in a register
Use ldr or str to access the variable
What is the .skip pseudo-op used for?
To allocate uninitialized space
When is the .global pseudo-op used?
To make a variable available to other compilation units.
What pseudo-op does the bss section usually only use?
.skip
When is bss memory zeroed?
Before program execution
Where are programmer-initialized constants put?
text section:
- is read only mem
- must be before or btw functions
What type of memory is the bss section
R/W