; safe.asm for testing protections within sections ; Assemble: nasm -f elf -l safe.lst safe.asm ; Link: gcc -o safe safe.o ; Run: safe ; Output: ; it should stop with a system caught error global main ; the standard gcc entry point extern printf ; the C function, to be called section .rodata ; read only data section, variables a: dd 5 ; int a=5; fmt: db "Bad, still running",10,0 section .text ; Code section. not writeable main: ; the program label for the entry point push ebp ; set up stack frame mov ebp,esp mov eax,0x789abcde mov [a],eax ; should be error, read only section push dword fmt ; address of ctrl string call printf ; Call C function add esp,4 ; pop stack, 1 push times 4 bytes mov esp, ebp ; take down stack frame pop ebp ; same as "leave" op mov eax,0 ; normal, no error, return value ret ; return