Operand type mismatch for idiv

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I am currently writing a compiler which produces x86-32 code.

However, I have a problem when trying to implement division.

idivl %ecx, %ebx 

This code gives me the following error:

Error: operand type mismatch for `idiv' 

Does anyone know why? The above lines are the only time idiv appears in my code.

回答1:

According to my reference, IDIV divides the 64-bit integer EDX:EAX by the provided register's value.

The idiv instruction divides the contents of the 64 bit integer EDX:EAX (constructed by viewing EDX as the most significant four bytes and EAX as the least significant four bytes) by the specified operand value. The quotient result of the division is stored into EAX, while the remainder is placed in EDX.

Syntax

idiv <reg32> idiv <mem> 

Examples

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 

and the remainder in EDX.

The idivl instruction behaves exactly like idiv, except idivl is a signed division.

See http://www.cs.virginia.edu/~evans/cs216/guides/x86.html

Another great ref: http://ref.x86asm.net/



回答2:

idivl only takes one argument. see here. it divides the contents of EDX:EAX by the contents of the argument



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!