        SYS_EXIT = 1
        SYS_READ = 3
        SYS_WRITE = 4
        STDIN = 0
        STDOUT = 1

.macro EXIT_
      	xor  %eax, %eax # return code of 0
        push %eax
        mov  $SYS_EXIT, %eax
        call _syscall
.endm

.macro GETCHAR
        mov  $1, %eax # size
        push %eax
        mov  $val, %ecx
        push %ecx # addr of val
        mov  $STDIN, %eax
        push %eax
        mov  $SYS_READ, %eax
        call _syscall
        add  $12, %esp
        cmp  $0, %eax
        jne  L0
        mov  $-1, %eax
        ret
L0:
        mov  $val, %ecx
        mov  (%ecx), %eax
        and  $255, %eax # mask out char value
.endm

.macro PUTCHAR
        mov  $1, %eax # size
        push %eax
        push %edi # addr of char to write
        mov  $STDOUT, %eax
        push %eax
        mov  $SYS_WRITE, %eax
        call _syscall
        add  $12, %esp
.endm

.section ".note.openbsd.ident", "a"
        .align 2
        .long 8
        .long 4
        .long 1
        .ascii "OpenBSD\0"
