tags:

views:

78

answers:

1

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:

  1. edx:eax
  2. 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