<- previous index next ->
See www.csee.umbc.edu/help/nasm/nasm.shtml for notes on using debugger.
A program that prints where its sections are allocated
(in virtual memory) is where.asm
; where.asm print addresses of sections
; Assemble: nasm -f elf -l where.lst where.asm
; Link: gcc -o where where.o
; Run: where
; Output: you need to run it, on my computer
; data a: at 8048330
; bss b: at 804840C
; rodata c: at 804956C
; code main: at 8049424
extern printf ; the C function, to be called
section .data ; Data section, initialized variables
a: db 0,1,2,3,4,5,6,7
fmt: db "data a: at %X",10
db "bss b: at %X",10
db "rodata c: at %X",10
db "code main: at %X",10,0
section .bss ; reserved storage, uninitialized
b: resb 8
section .rodata ; read only initialized storage
c: db 7,6,5,4,3,2,1,0
section .text ; Code section.
global main ; the standard gcc entry point
main: ; the program label for the entry point
push ebp
mov ebp,esp
push ebx
lea eax,[a] ; load effective address of [a]
push eax
lea ebx,[b]
push ebx
lea ecx,[c]
push ecx
lea edx,[main]
push edx
push dword fmt ; address of format string
call printf ; Call C function
add esp, 20 ; pop stack 5 push times 4 bytes
pop ebx
mov esp,ebp
pop ebp
mov eax,0 ; normal, no error, return value
ret ; return
<- previous index next ->