; where_64.asm print addresses of sections ; Assemble: nasm -g -f elf64 -l where_64.lst where_64.asm ; Link: gcc -g3 -m64 -o where_64 where_64.o ; Run: ./where_64 > where_64.out ; Output: you need to run it, results on my computer: ; data a: at ??? waries with computer and software ; bss b: at ??? ; rodata c: at ??? ; code main: at ??? ; ; to debug, typically after segfault ; gdb where_64 ; run ; backtrace ; optionally: disassemble x/60x main ; end with q y 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 %lX",10 db "bss b: at %lX",10 db "rodata c: at %lX",10 db "code main: at %lX",10,0 section .bss ; reserved storage, uninitialized b: resq 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 rbp mov rbp,rsp push rbx ; save callers registers mov rdi,fmt ; pass address of fmt to printf lea rsi,[a] ; using load effective address lea rdx,[b] ; using load effective address lea rcx,[c] ; using load effective address lea r8,[main] ; using load effective address mov rax,0 ; no float call printf ; Call C function mov rdi,fmt ; pass address of fmt to printf mov rsi,a ; just loading address mov rdx,b ; just loading address mov rcx,c ; just loading address mov r8,main ; just loading address mov rax,0 ; no float call printf ; Call C function pop rbx ; restore callers registers mov rsp,rbp pop rbp mov rax,0 ; normal, no error, return value ret ; return