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