[BITS 32]

extern printf
global main
 
%macro  prologue 0
        push    ebp
        mov     ebp,esp
%endmacro
 
%macro  prologue 1
        push    ebp
        mov     ebp,esp
        sub     esp,%1
%endmacro
 
%macro epilogue 0
        mov esp, ebp
        pop ebp
%endmacro
 
        section .bss
LC0:    resb 12
LC2:    resb 13
 
       
        global _start
        section .text
main:
        prologue
        push 123
        call itoa
	add esp,4

	push eax
	push C0
	call printf
	add esp,12
 
        ;mov ecx, eax    ; number string
        ;mov edx, ebx    ; length of string
        ;mov ebx, 1
        ;mov eax, 4
        ;int 0x80
 
        ;mov eax, 1
        ;mov ebx, 0
        ;int 0x80
 
        epilogue
       
itoa:
        prologue
        mov eax, [ebp+8]
        xor ecx, ecx          ; counter
        sub eax, 0
        jl negative
        jmp convert
negative:
        mov ebx, esp
        mov byte [ebx], 0x2D
        inc ecx
convert:
        xor edx, edx
        mov ebx, 10
        div ebx
        mov ebx, esp
        add ebx, ecx
        mov byte [ebx], dl
        add byte [ebx], 0x30
       
        inc ecx
        test al, al
        jnz convert
 
        mov eax, esp
        mov ebx, ecx
        epilogue
        ret

C0: db 'NUMBER = %s',10,13,0
