; EAX contains number ; ebx contains place to store it and will hold last used spot when done int_to_str PROC near push ebp mov ebp,esp sub esp,4 storebx equ [ebp-4] push EAX push ecx push edx mov storebx,ebx cmp eax,80000000h je negone ; This algorithm fails on largest negative cmp eax,0 jnl pos ; num is positive mov cl,'-' neg eax jmp bypass pos: mov cl,' ' bypass: ; EAX is positive now go for it mov ch,0 mov ebx,10 whileloop: cdq ; increase EAX to EDX:EAX idiv ebx ; EAX gets quotient, EDX remainder add dl,'0' ; should be in range 0-9 inc ch push dx ; save the digit cmp eax,0 jnz whileloop mov ebx,storebx ; Now construct the string cmp cl,'-' jne nums ; insert minus sign mov [ebx],cl inc ebx nums: shr ecx,8 ; shift the count down and get rid of sign numstart: pop ax mov [ebx],al inc ebx loop numstart i2sdone: pop edx pop ecx pop eax mov esp,ebp pop ebp ret negone: mov BYTE PTR [ebx],'-' inc ebx mov Byte PTR [ebx],'I' inc ebx mov BYTE PTR [ebx],'n' inc ebx mov Byte PTR [ebx],'f' inc ebx jmp i2sdone int_to_str endp