News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Routine question

Started by ragdog, May 14, 2010, 09:20:18 PM

Previous topic - Next topic

ragdog

Hi

I have a question to this routine

I found a source with a calcution and now wonder me waht make this


pushad
mov edi, [_Dest]
mov eax, [_IN]
mov ebx, 0Ah
xor ecx, ecx
     @@:
xor edx, edx
div ebx
add dl,30h
   push edx
inc ecx
   test  eax,eax
jnz @B
     @@:
pop edx
mov [edi], dl
inc edi
dec ecx
jnz @B
mov byte ptr [edi],0
popad

clive

Converts a 32-bit value into ASCII decimal
It could be a random act of randomness. Those happen a lot as well.

ragdog

Ahh ok

A simply way is us wsprintf %d for it

clive

Yes, sprintf(__Dest, "%u", __IN);

I would code it something like this, there are faster ways

pushad ; overkill

mov edi, [_Dest]; Output C string buffer
mov eax, [_IN] ; Input number 32-bit
mov ebx, 10 ; decimal, base 10
push 0 ; push NUL, end of stack/number marked
@@:
xor edx, edx ; Clear upper 32-bits for 64-bit div 32-bit
div ebx ; eax = edx:eax / ebx, edx = edx:eax % ebx
add edx,30h ; edx += '0'; edx is remainder from div 10
push edx ; push char
test eax,eax ; number consumed
jnz @B

@@: ; Unstack the number
pop edx ; pop char
mov [edi], dl ; *p++ = char
inc edi
test edx,edx ; NUL found
jnz @B

popad
It could be a random act of randomness. Those happen a lot as well.

qWord

The div can be replaced by an multiplication with the reciprocal - searching the forum you will find several threads about i2a,dw2a...
FPU in a trice: SmplMath
It's that simple!

dedndave

QuoteThe div can be replaced by an multiplication with the reciprocal - searching the forum you will find several threads about i2a,dw2a...

oh yah - and don't forget qWord's magic number program !!!   :bg

http://www.masm32.com/board/index.php?PHPSESSID=45aa5fcf6fed2c10a8876d7ef5cf362b&topic=9937.msg72815#msg72815

qWord

FPU in a trice: SmplMath
It's that simple!

dedndave

you can divide by 100,000,000 to extract 8 digits
save the quotient
then, divide that the remainder 10,000 to give you a 4-digit quotient and a 4-digit remainder
convert that remainder to 4 ASCII decimal digits
then convert that quotient to 4 ASCII decimal digits
then, recall the saved quotient and repeat
that is 16 digits - for a 64-bit value, you will only have 4 left

if you search the forum a bit, Drizz, JJ, Paul Dixon, and Lingo all have versions based on that