flat assembler
Message board for the users of flat assembler.

Index > Main > [Solved] use div twice causes a crash

Author
Thread Post new topic Reply to topic
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
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)

Code:
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
Post 26 Jun 2014, 00:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17450
Location: In your JS exploiting you and your system
revolution
div uses edx as a input also.
Post 26 Jun 2014, 00:19
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
thanks again revolution it works now!
Post 26 Jun 2014, 00:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.