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

%macro EXIT_ 0
        mov  eax, SYS_EXIT
      	push dword 0 ; return code of 0
        sub  esp, 4 ; system requires extra word
       	int  0x80
%endmacro

%macro GETCHAR 0
        mov  eax, SYS_READ
      	push dword 1 ; number of bytes to read
        push dword val ; where to save read byte
        push dword STDIN
        sub  esp, 4 ; system requires extra word
       	int  0x80
        add  esp, 16
        test eax, eax
        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 ; address of read byte
        mov  eax, [ecx] ; TODO use [val] directly
        and  eax, 255 ; mask out char value
%endmacro

%macro PUTCHAR 0
        mov  eax, SYS_WRITE
      	push dword 1 ; number of bytes to write
      	push dword edi ; address of byte to write
      	push dword STDOUT
        sub  esp, 4 ; system requires extra word
       	int  0x80
        add  esp, 16
%endmacro

