I just started learning assembly and can't quite understand how to add two 64 bit numbers. I'm using Free Pascal IDE, could you please give me working example with comments? I looked through relevant questions here, but it's still not clear for me
Asked
Active
Viewed 96 times
-1
-
In 32 or 64-bit mode? in 64-bit mode obviously a single add instruction is enough. In 32-bit mode long additions there are also tons of questions on this site already http://stackoverflow.com/questions/1652654/adding-64-bit-numbers-using-32-bit-arithmetic – phuclv Apr 08 '15 at 07:41
1 Answers
0
First of all x86 architecture doesn't (usually) allow operations on two memory operands. So at least one operand must be in the register.
Next, there are only a few ternary operations, so usually you work with two operands. That is you can't do (if to express in C notation) a = b + c
but only a += b
.
Next, you should specify which mode 32-bit or 64-bit you use. For 64-bit mode the addition is as simple as: add rax, rdx
(rax += rdx). For 32-bit mode you need two operations: add eax, edx
and then adc ecx, ebx
(ecx:eax += ebx:edx) Here adc
is 'addition with carry' - must be after carry flag is set by the first addition (but before it's changed by any other operation).

Matt
- 13,674
- 1
- 18
- 27