I’m trying to learn about assembly with the book “Programming from the ground up”. The book covers only 32 bit instructions. Is there a way to run the example codes on 64 bit Ubuntu system? I can’t understand the stuff on the man page of the GNU assembler but I heard the
-m32 flag should do it. But it’s not a recognized option.
How do I get the examples on the book to work with ease?
When your assembler and linker are x86_64 versions, the options to produce i386 (32-bit) output are
ld -m elf_i386
You don’t have to use
ld just because you’re working with assembly code.
gcc can be used, and in that case you would use
gcc -m32 -nostdlib myprog.s -o myprog
From the as man page:
Target i386 options:
I’m not sure if it works, just try
-m32 seems to ge the corresponding gcc flag.)
Creating a 32-bit executable on a 64-bit PC requires that you “warn” the linker that a 32-bit elf file is coming:
$ nasm -f elf -g -F stabs eat.asm
$ ld -o eat eat.o -melf_i386
That’s what the melf_i386 directive does: It tells ld that the eat.o file is an elf32 linkable object file. The invocation of NASM is the same as you’d use on a 32-bit PC.
Thanks @Jeff Duntemann