Issue
I am trying to run a simple assembly code who print hello world
global _start
section .text
_start:
;printing hello world
mov rax,1
mov rdi,1
mov rsi,texta
mov rdx,11
syscall
;exiting
mov rax,60
mov rdi,1
syscall
section .data
texta: db 'Hello world'
I assembled it by nasm
root@localhost:~# nasm -f elf64 do.asm -o do.o
But when I try to compile/run it , it show error
root@localhost:~# ld do.o -o do
ld: do.o: Relocations in
generic ELF (EM: 62)
ld: do.o: error adding
symbols: file in wrong format
Any way to solve it I am running it in Ubuntu-in-termux
Thanks in advance
Please solve it
Solution
But when I try to compile/run it , it show error
When I understand you correctly, the screen shot shows the target device (the device you generate code for).
Your assembly code is for 64-bit x86 CPUs, but your Android device uses an ARM CPU.
You cannot run assembly code for an x86 CPU on an ARM device.
You have to use an assembler for ARM and write ARM assembly code - maybe like this, in hello.S
.section .rodata
texta: .ascii "Hello world"
texta_len = . - texta @ define assemble-time constant length
#include <asm/unistd.h> @ only includes #define so can be included in a .S
.text
.global _start
_start:
@ Printing hello world
ldr r0, =1
ldr r1, =texta @ symbol address
ldr r2, =texta_len @ value of the assemble-time constant
ldr r7, =__NR_write @ call number from <asm/unistd.h>
svc #0 @ write(1, texta, len)
@@ And exiting
mov r0, #0
ldr r7, =__NR_exit
svc #0 @ exit(0)
See What is the interface for ARM system calls and where is it defined in the Linux kernel?
GAS (the GNU assembler) for ARM uses @
as the comment character, like in ARM manuals.
Answered By - Martin Rosenau