flat assembler
Message board for the users of flat assembler.

 Index > Main > Subtracting two 64bit values?
Author
Karl20001

Joined: 10 Nov 2005
Posts: 11
Karl20001 05 Feb 2006, 18:34
If i have a 64bit value in edx:eax, and another one in ecx:ebx

Code:
```sub eax,ebx
subb edx, ecx

;result in edx:eax
```

If eax>ebx no problem, if ebx>eax the borrow helps to give correct edx.
But then eax would be a negative number, that cant be right?!
05 Feb 2006, 18:34

Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 05 Feb 2006, 22:42
You just look at them as unsigned numbers. This is the right way to do 64-bit arithmetic:
Code:
```add eax,ebx
;edx:eax holds the result

sub eax,ebx
sbb edx,ecx
;edx:eax holds the result

;if carry occurs the eax would wrap around to 0FFFFFFFFh which is 4294967295
;in unsigned world but if you want you can consider it -1 too

multiplication is a bit harder and division a lot harder
```
05 Feb 2006, 22:42
Karl20001

Joined: 10 Nov 2005
Posts: 11
Karl20001 06 Feb 2006, 21:07