Hi,
Would anyone be willing to teach me how to convert the answer to ascii?

mov eax, 123456h
mov ecx, 123456h
mul ecx

Answer is in EDX:EAX (64bit number max:: EDX = 63->32 bits, EAX = 31-0 bits.

Thanks
Posted on 2003-05-29 21:37:21 by bgong68
Please, look at the FAQ or search the board for some great algorithms.

Sorry, I just tried looking and it is not as easy to find as I thought:

http://www.asmcommunity.net/board/index.php?topic=767&highlight=wsprintf
http://www.asmcommunity.net/board/index.php?topic=5197
http://www.asmcommunity.net/board/index.php?topic=1182&highlight=qw2a
Posted on 2003-05-29 21:47:20 by bitRAKE
The FPU can load 64-bit numbers, and then use FPU to convert to packed BCD format.
	push	edx

push eax
fild QWORD PTR [esp]
sub esp, 8
fbstp [esp]

A = least significant digit (4 bits each)
Q = most significant digit
s! = hight bit of byte is the sign of number

BA DC FE HG JI LK NM PO RQ s!
Look at the number in a debugger to see how the digits are arranged. Also, note that the FPU only loads signed QWORD integers, so the top bit of the result is not supported. And the FBSTP instruction only works to 18 digits. :)
Posted on 2003-05-30 08:52:09 by bitRAKE
bitRAKE's last algo is probably the easiest way to go.

The point was mentionned that the FPU only loads signed QWORD integers. Therefore, your code should use imul instead of the "mul" instruction for performing your multiplication, unless there is no possibility that either number could ever be negative.

The fbstp instruction needs a 10-byte variable or buffer to store the result. bitRAKE's code to change the ESP register by only 8 is most probably for maintaining stack alignment while leaving enough space for the data. (Actually, changing the ESP register by 4 would have been sufficient because 8 bytes were already taken by pushing EDX and EAX. The pushed value of EAX would have been trashed anyway by reserving only another 8 bytes.)

If you are using the stack for temporary storage such as suggested by bitRAKE, remember to also reset the ESP register at an opportune time.

Raymond
Posted on 2003-05-30 13:38:18 by Raymond
This worked for me:
	mov	eax, -1

mov edx, -1
mul edx


push eax
; set round mode to truncate
fstcw WORD PTR [esp] ; save for modify
and WORD PTR [esp],0F0FFh
; or WORD PTR [esp], 0E00h ; truncate/53-bit for 10 output lines
or WORD PTR [esp], 0F00h ; truncate/64-bit for 11 output lines
fldcw WORD PTR [esp]

push edx
push eax
sar edx, 31
fild QWORD PTR [esp]
push edx
fld fpc(<-18446744073709551616>)
; fld __2to64 ; -2^64
fimul DWORD PTR [esp]
fadd

fld st
fld fpc(<100000000>)
fxch
fprem
fbstp [esp]
fdiv
fbstp [esp+4]


mov edx, OFFSET __buffer

mov ecx, 20/2 - 1
@@: mov ax, 0
mov al, [esp + ecx]
ror ax, 4
ror ah, 4
add ax, "00"
mov [edx], ax
add edx, 2
dec ecx
jns @B

add esp, 16

invoke MessageBox, NULL,
OFFSET __buffer,
_T("64-bit Number:"), MB_OK or MB_ICONWARNING

__buffer db 256 dup (0)
Posted on 2003-05-31 08:19:35 by bitRAKE
Hi Bitrake,
Thanks for responding. The links you pointed me to were helpful. Everything seemed a little advanced for me, but I will try to go over everything again. Is it possible to place the result of the multiplication EDX:EAX into a QWORD? I am trying to do something like this.

.data
result qword 0

.code
mov eax,4000000000
mov edx,2
mul edx

;*************************
;after the mul instuction how do
;I place EDX:EAX into my
;variable result ?
;***************************

Thanks,
bgong68
Posted on 2003-05-31 12:15:36 by bgong68
EAX is the low part and goes first
EDX is high and goes second

mov DWORD PTR , eax
mov DWORD PTR , edx

...then you can...

fild result :)
Posted on 2003-05-31 12:55:06 by bitRAKE
Hi Bitrake,
Thanks for responding so fast! Why is it that I do not get the result I want?

.data
buffer db 255 dup (?)
format db "%lu",0
result qword ?

.code
start:
mov eax,4000000000
mov edx,2
mul edx

mov DWORD PTR , eax
mov DWORD PTR , edx

invoke wvsprintf, addr buffer, addr format, addr result
invoke MessageBox, 0, addr buffer, addr buffer, 0

ret
end start

The code above showed result to be 3705032704. Why won't it display the correct result?

If I change,

mov edx,2

to

mov edx,1

I get the correct result.

Thanks,
bgong68
Posted on 2003-05-31 13:18:21 by bgong68
try this format with wsprintf

format db "%I64d",0
Posted on 2003-05-31 19:23:30 by david