我已经尝试了 3 个多小时来弄清楚下一个程序出了什么问题。我要做的就是将x除以y,然后打印除法和模数的结果。此外,模数的 printf 和里面的 % 都搞砸了。有谁知道如何解决这个问题?我正在组装 IA32。假设我已经从用户那里得到了 x 和 y。
.section .rodata
format1: .string "Div : %d / %d = %d\n"
format2: .string "Mod : %d % %d = %d\n"
.text
.globl main
.type main, @function
# operation divide
movl x, %eax
cltd
idivl y
pushl %eax
pushl y
pushl x
pushl $format1
call printf
# operation modulo
pushl %edx
pushl y
pushl x
pushl $format2
call printf
我知道模数应该保存在 %edx 寄存器中,为什么它不起作用?非常感谢!丁:
编辑:好的,所以我将 %edx 保存在 %ebx 中,现在模可以正常工作。(如果我打印 %edx 中的内容,它会给出正确的模数)但是打印到屏幕上仍然不是我想要的。这是 x=2, y=4 的输出:
Divide : 2 / 4 = 0
Modulo : 2 %d = 4
我希望它看起来像这样:
Divide : 2 / 4 = 0.50
Modulo : 2 % 4 = 2