To add numbers in chunks of 32 bit you have to use the fact that add
set the CF
. So the low 32 bits are added as normal, the high ones are added with adc
which include the carry flag in the addition.
These macros should do
%macro add_double 4
mov eax, %1
mov edx, %2
add eax, %3
adc edx, %4
%endmacro
%macro add_doublev 2
mov eax, DWORD [%1]
mov edx, DWORD [%1+04h]
add eax, DWORD [%2]
adc edx, DWORD [%2+04h]
%endmacro
The add_double
takes 4 32 bits numbers, the first are the low 32 bits of the first number, the second the 32 high bits. The other two number are the same but for the second number. To add 0xff00000000
to 0x8800000000
use it as add_double 0, 0ffh, 0, 88h
.
The add_doublev
takes 2 addresses from which to fetch the two 64 bits numbers (in little endian). Use it as
num1 dd 0, 0ffh
num2 dd 0, 088h
add_doublev num1, num2
Both macros compute the result in EDX:EAX
, meaning that EDX
holds the upper 32 bits and EAX
the lower 32 bits.