1

I am writing some simple x86 assembly and when I run the following code

extern printf
global main

section .data
fmt: db "%d", 0x0a, 0

section .text
main:
    mov rax, 1
    
    ; sys_exit(0)
    mov rdi, 0
    mov rax, 60
    syscall

everthing runs fine.

However, if I leave off everything after the comment ; sys_exit(0) then I receive a Segmentation Fault.

Is calling sys_exit required or is something else happening?

sdasdadas
  • 23,917
  • 20
  • 63
  • 148
  • 3
    After the machine executes an instruction, it executes the next one. You didn't write any more, so it will try to execute whatever bytes happen to come next in memory. That will eventually fail one way or another, typically with a segfault as you saw. – Nate Eldredge Dec 20 '20 at 00:44

0 Answers0