Hi everybody. I am trying to figure out why this piece of code crashes
I am trying to write a int to string proc
(it may not be the most efficient but it was the only way I could think of doing it)
proc integertostring,integer,outputstring
;only works with integers from 0 to 2^32 or 4294967296
;get width of integer
mov esi,[integer]
mov edi,[outputstring]
.if esi < 10
add esi,48
mov dword[edi+0],esi
ret
.endif
.if esi >=10 & esi < 100
mov ebx,10
mov eax,esi
div ebx
add eax,48
add edx,48
mov dword[edi+0],eax
mov dword[edi+1],edx
ret
.endif
.if esi >=100 & esi < 1000
mov ebx,100
mov eax,esi
div ebx
add eax,48
mov dword[edi+0],eax
mov ebx,10
mov eax,edx
div ebx
add eax,48
add edx,48
mov dword[edi+1],eax
mov dword[edi+1],edx
ret
.endif
ret
endp
it works fine for any number between 0 and 9 | and 9 and 99
the problem is when the number is between 100 and 999(the thrid .if) it crashes
I found out the line that makes the proc crash is the second div. it makes no sense to me because the second div is the exact same as the first div in the second .if
I must be missing something here on how the div works and changes registers?
thanks
edit by revolution: added code tags