使用as组装x86程序集时无效的指令后缀

时间:2022-12-29 03:14:31

I wrote an assembly program that assemble successfully with as --32 when I use pushl and popl in the following code snippet:

我编写了一个汇编程序,当我在下面的代码片段中使用pushl和popl时,使用as32成功汇编:

  PrintHelloWorld:
    movl $10, %ecx
    PrintTenTimes:
      pushl %ecx
      movl $4, %eax
      movl $1, %ebx
      leal HelloWorld, %ecx
      movl $14, %edx
      int $0x80
      popl %ecx
    loop PrintTenTimes
    jmp ExitCall

But when I tried to assembly for 64-bit machines, I get the following error:

但是当我尝试组装64位计算机时,我收到以下错误:

ConditionalBranching.s: Assembler messages:
ConditionalBranching.s:51: Error: invalid instruction suffix for `push'
ConditionalBranching.s:57: Error: invalid instruction suffix for `pop'

So I change pushl and popl into pushq and popq, then I get the following error:

所以我将pushl和popl更改为pushq和popq,然后我收到以下错误:

ConditionalBranching.s: Assembler messages:
ConditionalBranching.s:51: Error: operand type mismatch for `push'
ConditionalBranching.s:57: Error: operand type mismatch for `pop'

How to remove this error and assemble successfully for 64-bit?

如何删除此错误并成功组装64位?

1 个解决方案

#1


I think you're most likely still trying to push the 32-bit eax rather than having upgraded your instruction correctly to:

我认为你很可能仍然试图推动32位eax,而不是正确地将你的指令升级到:

pushq %rax

That's based that on the fact that the error message is now complaining about an operand type mismatch rather than the suffix.

这是因为错误消息现在抱怨操作数类型不匹配而不是后缀。

As per the Intel documentation, the 32-bit register push instruction is not encodable in 64-bit mode:

根据英特尔文档,32位寄存器推送指令在64位模式下无法编码:

使用as组装x86程序集时无效的指令后缀

#1


I think you're most likely still trying to push the 32-bit eax rather than having upgraded your instruction correctly to:

我认为你很可能仍然试图推动32位eax,而不是正确地将你的指令升级到:

pushq %rax

That's based that on the fact that the error message is now complaining about an operand type mismatch rather than the suffix.

这是因为错误消息现在抱怨操作数类型不匹配而不是后缀。

As per the Intel documentation, the 32-bit register push instruction is not encodable in 64-bit mode:

根据英特尔文档,32位寄存器推送指令在64位模式下无法编码:

使用as组装x86程序集时无效的指令后缀