Question

Why the following code illegal in gas?

# cat -n gas.asm
1
2  .code64
3  pushb $12
4
# as gas.asm
gas.asm: Assembler messages:
gas.asm:3: Error: suffix or operands invalid for `push'

Isn't it matchs:

| Opcode* | Instruction | Op/En | 64-Bit Mode | Compat/Leg Mode | Description |
|      6A | PUSH imm8   | C     | Valid       | Valid           | Push imm8.  |

But, the following code works in NASM.

bits 64
push byte 12

Why gas get that error on X86-64 platform?

Thanks!

Was it helpful?

Solution

See this thread.

Quote:

I think what you are refering to is '0x6A PUSH imm8'. This does not push a byte onto the stack. It pushes a byte value, encoded as part of the instruction, as either a word (16-bits) or the CPU size [longword (32-bits) for 32-bit CPUs and quadword (64-bits) for 64-bit CPUs] depending on the stack size for the current CPU mode and size override prefixes.

In short, this is in effect a pushw. gas make this fact explicit and force you to use pushw $12.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top