Speaking of compiling 32-bit C programs, what about assembly language programs? Assembly varies considerably between machines as well, so it would be useful to know how to compile x86-32 software when you’re on x86-64. It’s relatively easy, so I’ll demonstrate the commands!
Compiling with the –32 flag
To compile 32-bit assembly programs with as you pass the –32 flag (found this under Target i386 options on the as man page). It’s pretty straight forward:
# as --32 -o example32bit.o example32bit.s
Linking using the -m flag
You’re not done yet! You still need to link the program and if you just tried that now you probably saw this:
# ld -o example32bit example32bit.o ld: i386 architecture of input file `example32bit.o' is incompatible with i386:x86-64 output
Jeez ld! What’s your problem?
Well, the linker needs to know the architecture as well. Try passing -m elf_i386 so ld will calm down a bit.
# ld -m elf_i386 -o example32bit example32bit.o
Finished!
Your program should run now.