GCC manual says that -m32
"generates code that runs on any i386 system". Assume I want to write a function that swaps the bytes of a 32 bit number:
.text .globl SwapBytes .type SwapBytes, @functionSwapBytes: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax bswapl %eax popl %ebp ret
However, the BSWAP
instruction is not supported on 80386, only since 80486. So I assemble gcc SwapBytes.s -march=i486 -c -o SwapBytes.elf
, as suggested by the cited manual. But then I get an error:
Assembler messages:Error: invalid instruction suffix for `push'Error: invalid instruction suffix for `pop'
But why? I thought, 32 bit stack was introduced with 80386. Ok, let's try with -march=pentium3
in case I missed something about 32 bit stack, but the same result. However, if I assemble just with the -m32
option, gcc
does not complain.
I thought maybe gcc
ignores the -march=...
options when assembling (and assumes -m64
?), but does not ignore the -m32
option? But what options can I use to specify the CPU I want to assemble for?