2

I am trying to start out with some assembly but I run into this error from the outset. Here are the details: I've written the file myself (following a video) so its not some import:

    global _start
    _start:
            mov eax, 1
            mov ebx, 42
            int 0x80

Pretty basic. I assemble and link it (

nasm -f elf32 ex1.asm -o ex1.o 

followed by

ld -m elf_i386 ex1.o -o ex1

checking the exit status at each stage with echo $?). It assembles and links fine. File gives:

ex1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped

My processor is a 64-bit AMD Ryzen 3 2200G, and my Win10 host and Ubuntu are also 64 bit (from what I've read running a 32 bit binary in a 64 bit environment is fine, right?). I have read many posts and they either discuss trying to run 64 on a 32, or corrupt imports or arch incompatibility (e.g. assembled for ARM) or more complex issues. This here is quite straight forward and for all intents and purposes it should simply run. However when I try it I get

-bash: ./ex1: cannot execute binary file: Exec format error

This is on Ubuntu installed through Windows 10 app store, 64 bit.

Any suggestions?

7
  • 1
    The code looks good to me, so what is the error message you're getting? – undercat applauds Monica May 31 '20 at 12:25
  • 2
    It's in the post title? – Paul_Pedant May 31 '20 at 12:37
  • 4
    "from what I've read running a 32 bit binary in a 64 bit environment is fine, right?" - well yes, but actually no – steeldriver May 31 '20 at 13:01
  • 1
    @xiLeon actually it should be possible in WSL2 - see for example Run 32-bit application on Ubuntu on Windows subsystem for Linux – steeldriver May 31 '20 at 13:24
  • 3
    Are you using WSL 1 ? WSL 2 is being shipped with a linux kernel and acts as a VM , so it seems like that you're running a linux in a VM. So everything (almost ) that works correctly in linux should work in WSL2 too. I tried your code and built it with the commands you specified and that worked very well in my linux system . So it should work in WSL2. – Parsa Mousavi May 31 '20 at 14:04
0

As pointed out in the comments already, the answer to the above nasm assembly problem in Ubuntu running on a Windows Subsystem for Linux (WSL) is to upgrade to WSL2. For anyone experiencing that issue, note:

  • if your Windows 10 is an older version than 2004, you will need to update that first.
  • Your Windows and WSL updates need to be done as Admin.

There are many links I used while playing around - couldn't remember all of them. However I recently came across:

https://www.youtube.com/watch?v=loC7VfgRT-I

which people may find a helpful starting point

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.