我正在学习 ia-32 并且在 32 位 Ubuntu 上一切正常,但是我切换到 64 位并开始使用标志 -m32 现在我无法在任何地方使用 DIV,无论寄存器的内容如何,它总是给我浮点异常...而且我确定我不会被零除。我正在使用 gcc 和 gdb。
这是最接近我的问题的问题:FPU IA-32 SIGFPE, Arithmetic exception
我试图将指令 fldcw 与 0x220 放在一起,但没有区别。
我的源代码:
.section .text
Division:
.int 0x220
str:
.asciz "%d"
.global binario # void binario(int)
binario:
pushl %ebp # prologo
movl %esp,%ebp #
finit
fldcw Division
pushl %ebx
pushl %ecx
pushl %edx
movl 8(%ebp),%eax # param x to eax
cmpl $0,%eax # compare x with 0
je fim # return recursive call
movl $2,%ecx # prepare division
divl %ecx # divide eax with 2
movl $0,%ecx # clean ecx
movb %al,%cl # put division result on cl
pushl %ecx # push x/2
call binario # recursive call
add $8,%esp # clean esp
movl $0,%ecx # clean ecx
movb %ah,%cl # put division rest on cl
pushl %ecx # push division rest
pushl $str # push string
call printf # call printf function
addl $8,%esp # clean esp
fim:
pushl %edx
pushl %ecx
pushl %ebx
movl %ebp,%esp # epilogo
popl %ebp #
ret
GDB 日志:
28 divl %ecx # divide eax with 2
2: $ecx = 2
1: $eax = 33
(gdb)
Program received signal SIGFPE, Arithmetic exception.
binario () at ex08.s:28
28 divl %ecx # divide eax with 2
2: $ecx = 2
1: $eax = 33