NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: merovich on October 09, 2012, 01:35:24 PM
-
Hi
I am having my first steps trying to use NASM with Linux RHEL6 and I am trying to compile a small test program
section .text
global _start
_start:
;Aquí va el código
;escribe (EAX=4) en la salida estándar (EBX=1) la cadena apuntada por ECX de longitud EDX.
mov edx,longitud
mov ecx,cadena
mov ebx,1
mov eax,4 ; es el system call WRITE
int 80h
;terminar la ejecución (EAX=1)
mov eax,1 ; es el system call EXIT
int 80h
section .data
;Aquí los datos inicializados
cadena db "Hola mundo",10,"$"
longitud equ $-cadena
I compile it without errors
[hmerovich@oc8467616104 ~]$ nasm -f elf ej1tp6.asm -o ej1tp6.o
[hmerovich@oc8467616104 ~]$
but when I try to link
[hmerovich@oc8467616104 ~]$ nasm -f elf ej1tp6.asm -o ej1tp6.o
[hmerovich@oc8467616104 ~]$
as the object format is elf32-i386 , i try
[hmerovich@oc8467616104 ~]$ ld -o ej1tp6 -b elf32-i386 ej1tp6.o
ej1tp6.o: could not read symbols: File format not recognized
Which format can I use to have LD recognize the NASM output?
Thanks you very much
[hmerovich@oc8467616104 ~]$ nasm -f elf ej1tp6.asm -o ej1tp6.o
[hmerovich@oc8467616104 ~]$
-
I think a minor change to the ld command line will fix it. "-m" rather than "-b", and "_" rather than "-"...
ld -o ej1tp6 -m elf_i386 ej1tp6.o
Although when I try the command line you're using, it seems to work for me(?). I'm still running a 32-bit system, so I don't really need that at all, just...
ld -o myfile myfile.o
...works for me. If I make a typo, and type...
ld -o myfile myfile.asm
I get a similar error.
There are a lot of options to ld, and it seems pretty flexible about what it will accept, so I'm a little confused about what you're seeing. Your code looks right, so that's a good start! If you can't get it to work, get back to us!
Best,
Frank
-
Frank
Thanks you very much
I try the command ld -o ej1tp6 -m elf_i386 ej1tp6.o
and it worked fine
Meanwhile I have tried to compile the asm using the NASM option ELF64 and I could link the obejct file without the -m option
Thanks again
Regards
-
Good! Yeah, "-f elf64" should work for "native" 64-bit ld, but I think you'll find it requires different code. I'm told you can still use "int 80h" and the old 32-bit system call numbers, but there are different numbers and "syscall" for 64-bit code. Your example may work, but something as simple as "push eax" will be illegal in 64-bit code. So I'm told... There are a few 64-bit examples in the "examples" section. Someday, 32-bit code will be as obsolete as 16-bit code is today, I imagine. When I upgrade my system (Real Soon Now, I keep saying), I'm going to be very busy getting back up to speed with 64-bit code! You might as well start learning it, but 32-bit code still works... for now...
Best,
Frank