section .data
c:      db    0

section .text

myputchar:
        pusha

        mov  [c], al
        mov  ecx, c  ; address of start of message
        mov  edx, 1  ; length of message
        mov  ebx,1   ; file descriptor (1: stdout)
        mov  eax,4   ; syscall number  (4: sys_write)
        int  0x80

        popa
        ret 

global _start   
        
_start:
        push 12340
        call print_integer
        ;; callee clears the stack

        mov al, 10
        call myputchar

        push -842101
        call print_integer

        mov al, 10
        call myputchar

        push 0
        call print_integer

        mov al, 10
        call myputchar


        mov eax, 1
        int 0x80

print_integer:
        push ebp
        mov  ebp, esp
        pusha

        mov eax, [ebp+8]
        
        cmp eax , 0
        jnl check2

        mov  al, '-'
        call myputchar
        mov eax, [ebp+8]        ; reload eax

        neg  eax
        push eax
        call print_integer
        jmp endfunc
        
check2:
        cmp eax, 10
        jge recur

        add  al, '0'
        call myputchar
        jmp endfunc     
        
recur:
        mov edx, 0
        mov ecx, 10
        div ecx

        push eax
        call print_integer

        mov al, dl
        add al, '0'
        call myputchar
        
endfunc:
        popa
        mov esp, ebp
        pop ebp
        ret 4