Hi 2 All.
I`ve got problem in multipling two big numbers.I`ve read iczelion`s tutorial but I`m stuck on this. ::)
;mov eax,dword ptr [edi] Our first num
;mov ebx,dword ptr [esi] 2nd num
mul ebx
After this we have a carry inside "edx" register.But How we can get our real result.
Any help or hint will be appreciated. :clap:
The MUL instruction leaves the result in EDX:EAX, meaning that the high-order 32 bits are in EDX and the low-order 32 bits in EAX. You could display the result registers separately, but this makes interpreting a decimal (base 10) result difficult at best (although it will work fine for hex, octal, or binary). Assuming that you are using the MASM32 package, another choice for a console app would be to use the CRT printf function to display the result as a 64-bit integer, something like this:
invoke crt_printf, chr$("%I64d%c"),edx::eax,10
Thanks.
I have another question.
Is there a function to Convert ascii string signed number into a 64 bit signed integer?
I know the function "atol" makes this for 32 bit signed integer.
Thanks in advance.
Try with sscanf, it is even better than atol/atof, because it returns the number of fields successfully converted and assigned.
invoke sscanf, string, format, &variable{, &variable, ...}
; example:
invoke sscanf, "12345678901234 0.1", "%I64d %f", offset variable64, offset variableDouble
Eax will be 2 on success (two values returned), 1 if only variable64 was returned, 0 on failure (nothing converted), EOF (-1) if ascii string is too short
And there is the CRT_atoi64 function (http://msdn.microsoft.com/en-us/library/hc25t012(VS.71).aspx).
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
invoke crt__atoi64, chr$("-9223372036854775808")
invoke crt_printf, cfm$("%I64d\n\n"),edx::eax
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
In case it's not obvious, 64-bit integers are normally returned in EDX:EAX.
Thanks for all replies. :clap: