
#       STACK_SIZE = 100000
        STACK_SIZE = 21000000

.section .bss
        .lcomm stack,       STACK_SIZE * 4  
        .lcomm val,         4

.section .text

	.global @SUBSTITUTE_ENTRY_NAME

_syscall: # only used by 32 bit OpenBSD
        int  $0x80
        ret

_my_exit:
	EXIT_ # sys_exit

_read_char:
        GETCHAR
        ret

_write_char:
        sub   $4, %edi
        PUTCHAR
        ret

my_mul:
        sub    $4, %edi
        mov    (%edi), %eax
        mov    %edi, %ecx
        sub    $4, %ecx
        mov    (%ecx), %ebx
        imul   %ebx
        mov    %eax, (%ecx)
        ret

my_div:
        sub    $4, %edi
        mov    (%edi), %eax
        cdq # sign extends edx if eax is negative
        mov    %edi, %ecx
        sub    $4, %ecx
        mov    (%ecx), %ebx
        idiv   %ebx
        mov    %eax, (%ecx)
        ret

my_mod:
        sub    $4, %edi
        mov    (%edi), %eax
        cdq # sign extends edx if eax is negative
        mov    %edi, %ecx
        sub    $4, %ecx
        mov    (%ecx), %ebx
        idiv   %ebx
        mov    %edx, (%ecx)
        ret

my_abs:
        mov    %edi, %ecx
        sub    $4, %ecx
        mov    (%ecx), %eax
        test   %eax, %eax
        jg     L11
        neg    %eax
        mov    %eax, (%ecx)
L11:
        ret

@SUBSTITUTE_ENTRY_NAME:
        mov    $stack, %eax
