; priv_64.asm for testing that average user ; can not execute privileged instructions ; Assemble: nasm -f elf64 priv_64.asm ; Link: gcc -o priv_64 priv_64.o ; Run: ./priv_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 fmt: db "bad! Still running",10,0 ; The printf format, "\n",'0' section .text ; try to halt the computer main: ; the program label for the entry point push rbp ; set up stack frame hlt ; should be error, only allowed in CPL=0 mov rdi,fmt ; address of format string mov rax,0 call printf pop rbp mov rax,0 ; normal, no error, return value ret ; return