0

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.....

  • @NotTheDr01ds could use some help here........ – Hrithik Raj Nov 04 '21 at 19:24
  • Look like you need to do some special [hoop jumping](https://github.com/microsoft/wsl/issues/2468) to get this working. – 500 - Internal Server Error Nov 04 '21 at 19:28
  • The simple solution is to write 64 bit code. – Jester Nov 04 '21 at 19:37
  • 1
    @HrithikRaj Oh, it's been way too many decades since I've done any assembly ;-). But yes, see the Github issue that 500 posted, but realize that it starts with WSL1 a few years back. Also note [this question](https://stackoverflow.com/q/67782451/11810933). – NotTheDr01ds Nov 04 '21 at 23:40
  • 2
    [Does WSL 2 really support 32 bit program?](https://stackoverflow.com/q/61300194) shows how to check that you're really fully using WSL2, not WSL1 which doesn't support 32-bit programs. Your `uname -a` has a kernel version name ending with WSL2, but I don't know if that's definitive. You'd hope it would be, but given the error you're getting, it appears not. Those are the right build commands. – Peter Cordes Nov 05 '21 at 01:34
  • @Peter Cordes: `Linux DESKTOP-JO8V9QJ 5.10.16.3-microsoft-standard-WSL #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux` Where does this say WSL2 ? – ecm Nov 05 '21 at 08:35
  • 1
    @ecm: 7 minutes ago, it said WSL2 instead of WSL. Apparently the querent somehow added a 2 when copy/pasting it, or copy/pasted from the wrong thing, and just edited it after my comment made them double-check. – Peter Cordes Nov 05 '21 at 08:39
  • @PeterCordes that 2 was an error i edited it now and Installed WSL 2 and the program works .....thanks – Hrithik Raj Nov 05 '21 at 08:42

0 Answers0