NASM Coding: Basics - Program Examples

  1. ; A program that adds two constants and exits by returning the addition result.
    
    section .text
        global _start
    
    _start:
        mov rax, 5    ; Put 5 in rax
        mov rbx, 3    ; Put 3 in rbx
        add rax, rbx  ; Compute: rax += rbx
    
        mov rdi, rax  ; Put rax (= 3 + 5) in rdi
        mov rax, 60   ; Put the 'exit' syscall code in rax
        syscall       ; Call _exit(rdi), which is _exit(8)