How can I use Gas ('as') to assemble source to a 32 bit binary on 64 bit Linux?
This is for the purpose of following 32 bit tutorials without the hassle of having to change all the pointers and lots of instructions to quad words.
Thanks,
Chris.
P.S. I can easily do this in C...
chris@chris-linux-desktop:~$ cat test.c
#include "stdio.h"
int main() {
printf("hello world");
return 0;
}
chris@chris-linux-desktop:~$ gcc test.c -o test64
chris@chris-linux-desktop:~$ gcc -m32 test.c -o test32
chris@chris-linux-desktop:~$ file test32
test32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
chris@chris-linux-desktop:~$ file test64
test64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
Mostly compiler(gcc or clang) of C and C++, nowadays come with default 64-bit version.
the 32bit compiler can compile into 32bit machine code which can be run only on 32bit and 64bit microprocessor. But not less than 32 bit. Follow this answer to receive notifications.
The -m32 flag tells GCC to compile in 32-bit mode.
Use as
with the option "--32", like
as --32 source.s -o objectfile
Or you can just use gcc to assemble and link an assemler source file. gcc recognizes it by the ending.
gcc -m32 source.s -o executable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With