; syscall0s_64.asm demonstrate operating system kernel calls ; Compile: nasm -f elf64 syscall0s_64.asm ; Link ld -m64 -o syscall0s_64 syscall0s_64.o ; Run: ./syscall0s_64 ; section .data msg: db "syscall0s_64.asm running",10 ; the string to print, 10=crlf len: equ $-msg ; "$" means here, len is a value, not an address msg2: db "syscall0s_64.asm finished",10 ; no 0 needed len2: equ $-msg2 msg3: db "syscall0s_64.asm opened",10 len3: equ $-msg3 msg4: db "syscall0s_64.asm read",10 len4: equ $-msg4 msg5: db "syscall0s_64.asm open fail",10 len5: equ $-msg5 msg6: db "syscall0s_64.asm another open fail",10 len6: equ $-msg6 msg7: db "syscall0s_64.asm read fail",10 len7: equ $-msg7 name: db "syscall0s_64.asm",0 ; "C" string, zero needed fd: dq 0 ; file descriptor, int flags: dq 0 ; hopefully read-only section .bss line: resb 8193 ; read/write buffer 16 sectors of 512 lenbuf: resq 1 ; number of bytes read extern open global _start section .text _start: ; header msg ; these 5 lines are like printf mov rdx,len ; arg3, length of string to print mov rcx,msg ; arg2, pointer to string mov rbx,1 ; arg1, where to write, screen mov rax,4 ; write command to int 80 hex int 0x80 ; interrupt 80 hex, call kernel mov rbx,0 ; exit code, 0=normal mov rax,1 ; exit command to kernel int 0x80 ; interrupt 80 hex, call kernel