2011-12-06 52 views
0

我目前正在編寫一個生成x86-32代碼的編譯器。idiv的操作數類型不匹配

但是,我在嘗試實施除法時遇到問題。

idivl %ecx, %ebx 

此代碼給我下面的錯誤:

Error: operand type mismatch for `idiv' 

有誰知道爲什麼嗎?以上幾行是唯一的時間idiv出現在我的代碼中。

+3

我可能錯了,但不是'idiv'單個操作數指令嗎? – Mysticial

+0

@Mysticial - 是的,它計算'edx:eax/r32',其中'edx:eax'是edx'和'eax'的一個按位串聯以形成一個64位值,'r32'是任何32位寄存器或指針。結果放在'eax'中,其餘部分放在'edx'中。 – Polynomial

回答

6

根據我的參考,IDIV用提供的寄存器值除以64位整數EDX:EAX

idiv — Integer Division

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.

idivl指令的行爲完全像idiv,除了idivl是一個有符號的除法。

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

另一位偉大的裁判:http://ref.x86asm.net/

+0

非常感謝! – Sven

+0

很高興爲您提供幫助:] – Polynomial

+0

這可能對您有些用處,它本質上是一個常用說明的laymen條件列表,以及它們的作用:http://programminggroundup.blogspot.com/2007/01/appendix-b- common-x86-instructions.html – Polynomial

3

idivl只需要一個參數。見here。 它將EDX:EAX的內容除以參數的內容

+0

也謝謝你:-) – Sven