Invalid instruction suffix for push when assembling with gas

vitaut picture vitaut · Jun 7, 2011 · Viewed 33.4k times · Source

When assembling a file with GNU assembler I get the following error:

hello.s:6: Error: invalid instruction suffix for `push'

Here's the file that I'm trying to assemble:

        .text
LC0:
        .ascii "Hello, world!\12\0"
.globl _main
_main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %eax
        movl    %eax, -4(%ebp)
        movl    -4(%ebp), %eax
        call    __alloca
        call    ___main
        movl    $LC0, (%esp)
        call    _printf
        movl    $0, %eax
        leave
        ret

What is wrong here and how do I fix it?

The problem is somewhat related to this question although errors and instructions in questions are different.

Answer

Xiao Jia picture Xiao Jia · Nov 30, 2012

Prepend .code32 as your first line.

--32 option will change the target to 32 bit platform.