我目前正在编写一个生成x86-32代码的编译器。
但是,我在尝试实施部门时遇到了问题。
idivl %ecx, %ebx
此代码给出了以下错误:
Error: operand type mismatch for `idiv'
有谁知道为什么?以上行是idiv
出现在我的代码中的唯一时间。
答案 0 :(得分:6)
根据我的参考,IDIV
将64位整数EDX:EAX
除以提供的寄存器值。
idiv - 整数分部
idiv指令除以64位整数EDX的内容:EAX(通过查看EDX构成最重要的四个字节 由指定的操作数和EAX作为最不重要的四个字节 值。除法的商结果存储在EAX中,而 其余部分放在EDX中。
语法
idiv <reg32> idiv <mem>
实施例
idiv ebx ; divide the contents of EDX:EAX by the contents of EBX. Place the quotient in EAX and the remainder in EDX. idiv DWORD PTR [var] ; divide the contents of EDX:EAS by the 32-bit value stored at memory location var. Place the quotient in EAX
和EDX中的其余部分。
idivl
指令的行为与idiv
完全相同,但idivl
是有符号的除法。
请参阅http://www.cs.virginia.edu/~evans/cs216/guides/x86.html
另一个很好的参考:http://ref.x86asm.net/
答案 1 :(得分:3)
idivl只接受一个参数。见here。 它通过参数
的内容划分EDX:EAX的内容