How can I substract 64 bit numbers using 386 assembler?
+9
A:
The idea is to use the SBB (sub with borrow) instruction. For instance, if I have two numbers:
edx:eax
ecx:ebx
then this will put the difference in edx:eax
:
sub eax, ebx
sbb edx, ecx
The idea is that you can subtract each part separately, but you need to borrow from the MSBs to the LSBs. SBB does just that:
SBB dest, src
means:
dest <-- dest - src - EFLAGS.CF
Which is convenient because:
SUB dest, src
means:
dest <-- dest - src
EFLAGS.CF <-- borrow from subtraction
Nathan Fellman
2010-06-16 19:14:49