Reputation: 1121
GAS is rejecting all my pushl's with
"wrong instruction prefix"
. I can't figure out why...(sample dummy code)
.section .text
.global _start
_start:
movl $10, %eax
pushl %eax
movl $1, %eax
int $exit
.data
.equ exit, 0x80
I also couldn't do
int 0x80
directly in the script above.It says
operand size mismatch for `int'
I've tried int 80H
, doesn't work too.
What am I missing?
Upvotes: 1
Views: 1365
Reputation: 58517
int 0x80
should be int $0x80
(note the $
, since it's an immediate operand)
Regarding pushl
, I'm guessing that you're using a version of the GNU assembler that was configured for 64-bit targets. push r32
is non-encodable in 64-bit mode as you can see in the description for push
in Intel's Software Developer's Manual. You could use pushq %rax
instead.
However, looking at your code it seems like you're writing a 32-bit application, so you should probably tell the assembler to use 32-bit mode instead (pass --32
to as,
or -m32
to gcc
).
If you're linking with ld
you'll also have to specify an emulation mode for ld
with -m
, e.g. -m elf_i386
(to find out which emulation modes you have available, use ld -V
). An alternative would be to link with gcc
, e.g. gcc -m32 foo.o
.
Upvotes: 3
Reputation: 36649
It looks like you are on an x86_64
architecture, but trying to assemble x86
specific code. You need to pass the --32
flag to gas
:
$ as --32 -ofile.o file.asm
With this command line, I was able to assemble your code - without the flag, I am getting the wrong instruction prefix
error.
I also couldn't do
int 0x80
The int
instruction requires one immediate operand (the interrupt vector number), and gas
requires immediate operands to be prefixed with $
(which you correctly did for your mov
instructions):
int $0x80
Upvotes: 2