0

我需要添加两个大数字的帮助(例如,大我的意思是不适合eax)。我知道我必须使用adc,但它并没有给我带来好的结果。

SYSCALL = 0X80
STDIN = 0
STDOUT = 1
SYSREAD = 3
SYSWRITE = 4
SYSEXIT = 1

.section .data

a1: .long 4000000000
a2: .long 4000000000
equals: .long 0

.section .text
.globl _start

_start:

xor %edx, %edx

movl a1, %eax
movl a2, %ebx
adc a2, %eax
movl %eax, equals

mov $SYSEXIT, %eax
int $SYSCALL

我在 gdb 下用 print equals 检查结果。

4

1 回答 1

0

不是最时尚的汇编程序,但这样的东西应该可以工作;

a1: .long 4000000000
a2: .long 4000000000
result_lo: .long 0
result_hi: .long 0

movl a1, %eax                ; load a1 into %eax
addl a2, %eax                ; add a2 to %eax
movl %eax, result_lo         ; store low 32 bits of result

movl $0, %eax                ; clear %eax
adcl $0, %eax                ; add carry + 0 to %eax
movl %eax, result_hi         ; store high 32 bits of result

ADC添加两个操作数 + 最后一个操作的进位。无需将其用于低 32 位,但对于第二个 32 位,您将希望最后一个添加的溢出结转。

于 2013-04-26T16:45:59.903 回答