I write a simple assembly function sum64, which add ecx:ebx+edx:eax, its works correct with positive number, but not in negative.
sum64:
add ebx,eax
adc ecx,edx
ret
Example:
edx = 1d1h
eax = a94a2003
ebx = FFFFFFFF
ecx = 00000000
The correct result is 1D1A94A2002h but my function return ecx:1d2h ebx:a94a2002, it is incorrect because the first “add” set the carry, why?
How to solve this?
Thanks the answers.
The numbers you are testing are:
Neither are negative (in 64-bit two’s complement representation) so sum to the result that you are getting.
-1as a 64-bit negative number would beffffffffin bothecxandebxwhich would give the result that you were originally expecting.