I am starting to learn x86 Assembly Programming, following this Tutorial and I wrote a Hello World Program saved as hello.asm
section .text
global _start
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov eax,1
int 0x80
section .data
msg db 'Hello, world!', 0xa
len equ $ - msg
I then used nasm as
nasm -f elf32 hello.asm
and got the object file hello.o
then I used ld as
ld -m elf_i386 -o hello hello.o
I then got the hello binary file, executing it with ./hello I get
./hello: cannot execute binary file: Exec format error
I have 64 bit OS,output of "uname -a"
uname -a
Linux DESKTOP-JO8V9QJ 5.10.16.3-microsoft-standard-WSL #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux
the hello binary file is 32 bit , output of file ./hello is
file ./hello
./hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
Now x64 is supposed to be Backward Compatible, that means it should be able to run this binary... My Question is , is there a problem in the Code or is there something wrong with my instance of Kali on WSL which I am using to execute this because WSL has Given me Problems earlier and what is the solution for this"Exec Format Error" ?
Other stack overflow articles come close to this issue but nothing related to running it on WSL...
EDIT 1: wsl -l -v gives
NAME STATE VERSION
- kali-linux Running 1
and I didn't knew that WSL doesnt Support 32 bit so , Upgrded to WSL2 and it works perfectly.....