; 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 ; save callers registers lea eax,[a] ; using load effective address push eax lea ebx,[b] push ebx lea ecx,[c] push ecx lea edx,[main] push edx push dword fmt ; address of ctrl string call printf ; Call C function add esp, 20 ; pop stack 5 push times 4 bytes mov eax,a ; just loading address push eax mov ebx,b push ebx mov ecx,c push ecx mov edx,main push edx push dword fmt ; address of ctrl string call printf ; Call C function add esp, 20 ; pop stack 5 push times 4 bytes pop ebx ; restore callers registers mov esp,ebp pop ebp mov eax,0 ; normal, no error, return value ret ; return