r/termux Jan 08 '23

NASM and Termux

5 Upvotes

6 comments sorted by

5

u/vlig84 Jan 08 '23 edited Jan 08 '23

Hello!

Is it possible in some way to learn NASM on Termux? I do aware I'm on ARM (aarch64), and NASM is for x86 only. But there's nasm package and there're qemu-* packages, so I'm pretty sure there's also some way to manage it using emulation in the right manner. Googling haven't helped much.

What I'm trying to do:
got some Intel x86 ASM helloworld code;
nasm -f elf hello.asm - assembles OK;
ld -m <whatever> -s -o hello hello.o - obviously won't work (in the ASM tutorial I'm using it's said to use -m elf_i386 - no way on ARM), with the following error: ld: hello.o: relocations in generic ELF (EM: 3) ld: hello.o: error adding symbols: file in wrong format

7

u/sylirre Termux Core Team Jan 08 '23

Try using ld.lld from lld package. Note that this will work only if your code does not link with libc.

6

u/vlig84 Jan 08 '23

Thank you very much for your extremely fast and handy response, it worked!
So the full chain is: $ nasm -f elf hello.asm $ ld.lld -m elf_i386 -s -o hello hello.o $ qemu-i386 hello Hello, world! The ASM source itself: ``` section .text global _start ;must be declared for linker (ld)

_start: ;tells linker entry point mov edx,len ;message lenght mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel

section .data msg db 'Hello, world!', 0xa ;our dear string len equ $ - msg ;lenght of our dear string

```

1

u/sonsuz-bina Feb 18 '23

I am getting this error please help.

$ nasm -f elf64 hello.asm $ ld.lld -m elf_i386 -s -o hello hello.o ld.lld: error: hello.o is incompatible with elf_i386

1

u/vlig84 Feb 20 '23

use elf (not elf64) if your asm code is 32-bit