External Data & Text Flashcards

1
Q

In C, where are local (automatic) variables allocated?

What is their scope?

What is their lifetime?

A

In the stack frame

The block of code where declared

The life of the block of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where are static local variables stored?

What is the scope?

What is the lifetime?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where are global variables stored?

What is the scope?

What is the lifetime?

A

In a separate section of RAM

Global (even throughout files)

Life of program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where are static local variables stored?

What is the scope?

What is the lifetime?

A

In a separate location in RAM

Local to file from declaration point onwards

Lifetime: life of program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 3 sections of memory that programs may allocate?

A

.text
.data
.bss

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the text section contain?

A

Program text (machine code)

Read-only, programmer-initialized data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What will happen if you try to write to text memory?

A

A segmentation fault will occur because text is read-only mem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the data section contain?

A

Programmer-initialized data

Is read/write memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does bss stand for and what does it have?

A

Block Starting Symbol

Reserved for zero-initialized data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where are the text, data and bss sections stored?

A

In low memory, just after the OS kernel section (see diagram)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you indicate that what follows goes into a particular section?

A

Use pseudo-ops
.text (default section when assembling)
.data
.bss

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The assembler uses a _____ counter for each section (like text, data, bss)

A

Location counter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the location counter do?

A
  • starts at 0 and increases as instructions and data are processed
  • final step of assembly gathers all code and data into appropriate sections
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the order of sections loaded when the OS loads a program into RAM?

A
  1. text & data
  2. bss section is zeroed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

External variables: low or high level concept?

A

low

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are external variables and where are they allocated?

A

Non-local variables used to implement C language global & static variables. Allocated in the data or bss sections

17
Q

What pseudo-ops can be used to allocate & initialize external variables? What is the general form for allocating& initializing EVs?

A

.byte, .hword, .word, .dword

check notes

18
Q

What do the labels of external variables represent?

A

64-bit addresses

19
Q

External variables: how to put the address in a register and how to access one

A

Use adrp & add to put the address in a register

Use ldr or str to access the variable

20
Q

What is the .skip pseudo-op used for?

A

To allocate uninitialized space

21
Q

When is the .global pseudo-op used?

A

To make a variable available to other compilation units.

22
Q

What pseudo-op does the bss section usually only use?

A

.skip

23
Q

When is bss memory zeroed?

A

Before program execution

24
Q

Where are programmer-initialized constants put?

A

text section:
- is read only mem
- must be before or btw functions

25
Q

What type of memory is the bss section

A

R/W