I read this article , and at some point he gives me this nasm program:
; tiny.asm BITS 32 GLOBAL main SECTION .text main: mov eax, 42 ret
And tells me to run the following commands:
$ nasm -f elf tiny.asm $ gcc -Wall -s tiny.o
I got the following error:
ld: warning: option -s is obsolete and being ignored ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64) Undefined symbols for architecture x86_64: "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status
I decided to guess what might be the problem, and changed the BITS line as follows:
BITS 64
But then when I run nasm -f elf tiny.asm
, I get:
tiny.asm:2: error: `64' is not a valid segment size; must be 16 or 32
How do I change the code to work on my machine?
Edit:
I took Alex's advice from the comments and uploaded a newer version. Nonetheless,
./nasm-2.09.10/nasm -f elf tiny.asm
complains
tiny.asm:2: error: elf32 output format does not support 64-bit code
On the other hand,
./nasm-2.09.10/nasm -f elf64 tiny.asm gcc -Wall -s tiny.o
complains
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64) Undefined symbols for architecture x86_64: "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status