; safe_64.asm for testing protections within sections ; Assemble: nasm -f elf64 safe_64.asm ; Link: gcc -o safe_64 safe_64.o ; Run: ./safe_64 ; 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, constants a: dq 5 ; long 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 rbp ; set up stack frame mov rax,0x789abcde mov [a],rax ; should be error, read only section mov rdi,fmt ; address of format string mov rax,0 call printf pop rbp mov rax,0 ; normal, no error, return value ret ; return