drdot
drdot

Reputation: 3347

invalid instruction suffix when assembling x86 assembly with as

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

  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:

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:

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?

Upvotes: 0

Views: 1601

Answers (1)

paxdiablo
paxdiablo

Reputation: 881653

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

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:

enter image description here

Upvotes: 1

Related Questions