操作数类型不匹配的idiv

时间:2011-12-06 06:45:00

标签: assembly x86

我目前正在编写一个生成x86-32代码的编译器。

但是,我在尝试实施部门时遇到了问题。

idivl %ecx, %ebx

此代码给出了以下错误:

Error: operand type mismatch for `idiv'

有谁知道为什么?以上行是idiv出现在我的代码中的唯一时间。

2 个答案:

答案 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的内容