bits 64

section .data
hello db 0x0A, 0x0D, "TEST PROGRAM...", 0x0A, 0x0D, 0
filename db "wow.txt", 0

section .text

_start:
    mov rax, 0x1    ;sys_write
    mov rdi, 0x1    ;stdout
    lea rsi, [rel hello]
    mov rdx, 19     ;count
    int 0x80

    ; Open a file
    mov rax, 0x2            ;sys_open
    lea rdi, [rel filename] ;filename
    mov rsi, 0x0            ;flags
    int 0x80

    mov rdi, rax            ;fd
    mov rax, 0x0            ;sys_read
    lea rsi, [rel buf]      ;buf
    mov rdx, 33             ;count
    int 0x80

    mov rax, 0x1        ;sys_write
    mov rdi, 0x1        ;stdout
    lea rsi, [rel buf]  ;buf
    mov rdx, 33         ;count
    int 0x80

    mov rax, 0x3        ;sys_close
    mov rdi, 0x3        ;fd
    int 0x80

; when we are ready to have an os specific toolchain,
; this bit (exit & loop) should be appended at the end of every
; C program we compile.

.end:
    mov rax, 0x3C
    mov rdi, 0x0
    int 0x80

.loop:
    jmp .loop

section .bss
buf resb 10