The MASM Forum Archive 2004 to 2012

Project Support Forums => IDE Development and Support => RadAsm Support Forum => Topic started by: CObject on July 13, 2005, 09:47:45 AM

Title: 64-bits arithmetic
Post by: CObject on July 13, 2005, 09:47:45 AM
Hi all !

What do you think :
which's the best way to compare 2 LARGE_INTEGERs ?

Without using MMX or FPU !
Title: Re: 64-bits arithmetic
Post by: farrier on July 13, 2005, 12:09:54 PM
CObject,

Look at:

http://www.masmforum.com/simple/index.php?topic=2188.0

hth,

farrier
Title: Re: 64-bits arithmetic
Post by: Eóin on July 13, 2005, 12:37:54 PM
Assuming one is in eax:edx and the other in ebx:ecx (Just for simplicity, easily changed) try the following

cmp edx,ecx
jne @F
cmp eax,ebx
@@:

For unsigned 64bit number the state of the flags should now tell you which is bigger/smaller or if both equal.
Title: Re: 64-bits arithmetic
Post by: CObject on July 13, 2005, 04:15:38 PM
I sovle my problem  :8)
The following best fits for my needs


.386
.model flat,stdcall

LARGE struct
lo dd ?
hi dd ?
LARGE ends

;#######################  CONST DATA  ###########################
.const

;#######################  INITDATA  #############################
.data
largeValue1 LARGE<09C370555h,0000004Dh> ; 333 333 333 333
largeValue2 LARGE<0BD7A038Eh,00000033h> ; 222 222 222 222

;######################  UNINIT DATA  ###########################
.data?

;#########################  CODE  ###############################
.code
start:
main    proc

        ; largeValue1
        mov eax,largeValue1.lo
        mov ebx,largeValue1.hi

        ; largeValue2
        mov ecx,largeValue2.lo
        mov edx,largeValue2.hi

        ; largeValue1 - largeValue2
        sub eax,ecx
        sbb ebx,edx

        ; compare
        shl ebx,1
        jc nega
        or eax,ebx  ;cmp eax,0
        jnz pos
        PrintText "largeValue1 == largeValue2"
        jmp quit
pos:    PrintText "largeValue1 > largeValue2"
        jmp quit
nega:   PrintText "largeValue1 < largeValue2"

quit:   mov eax,0
        ret
main    endp

;###################  Functions definition  #####################

        end start
Title: Re: 64-bits arithmetic
Post by: Eóin on July 13, 2005, 08:08:17 PM
Nice method :).