External Data & Text
External Data & Text
External Variables
There
Zero initialized.
Non-zero initialized.
When a program is loaded into memory, the program text,
initialized variable, and zero initialized variables are
loaded into different regions (text, data, and bss
sections, respectively.) of memory, typically starting at
0x2000 byte boundary.
Text Section
Text
Data Section
Data
Variables
must be initialized.
Example:
A)
Array: .word 0, 1, 2, 3, 4, 5
B)
NoMem:
.byte
Array2:
.byte 1, 2, 3, 4
NoMem has the same address as Array2
BSS Section
BSS
.common
Accessing Variables
Use set instruction to get the address of a variable into a
register.
Use load or store instruction to read/write from/to the
variable.
Example
.section .data
a: .word 5
.section .text
set a, %l0 !get the address of a to %lo
ld [%l0], %o0
!get the value of a into %o0
What is the content of %o0 now????
Example cont.
.section .data
b: .byte 9
.section .text
set b, %l1 ! Load the address of b to %l1
mov 10, %l2 ! Move 10 to %l2
stb %l2, [%l1] ! Store value 10 into b
What is the value of b now????
set
Switch statement
Covered
in previous chapters
Compilation
Multiple