%define SYS_EXIT 1
%define SYS_READ 3
%define SYS_WRITE 4
%define STDIN 0
%define STDOUT 1

%define _START _start

%macro EXIT_ 0
      	xor  eax, eax ; return code of 0
        push eax
        mov  eax, SYS_EXIT
        call _syscall
%endmacro

%macro GETCHAR 0
        mov  eax, 1 ; size
        push eax
        mov  ecx, val
        push ecx ; addr of val
        mov  eax, STDIN
        push eax
        mov  eax, SYS_READ
        call _syscall
        add  esp, 12
        cmp  eax, 0
        jne  L0
        mov  ebx, 1
        mov  edx, eof_reached ; TODO use [eof_reached] directly
        mov  [edx], ebx
        mov  eax, -1
        ret
L0:
        mov  ecx, val
        mov  eax, [ecx]
        and  eax, 255 ; mask out char value
%endmacro

%macro PUTCHAR 0
        mov  eax, 1 ; size
        push eax
        push edi ; addr of char to write
        mov  eax, STDOUT
        push eax
        mov  eax, SYS_WRITE
        call _syscall
        add  esp, 12
%endmacro

section .note.openbsd.ident
        align 2
        dd 8
        dd 4
        dd 1
        db 'OpenBSD',0
        dd 0
        align 2
