1

So I've been trying to learn x86 assembly with nasm. The operating System is ubuntu, using WSL2. I would assemble my file as shown here:

 nasm -f elf32 file.asm

no errors, so I would link it with ld, like this:

ld -m elf_i386 -o file file.o

no errors again, but when I run the executable produced(./file), I get the following error:

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

I've been stuck for a while now. I know that my code I've written has no errors, as I tested it on an online assembler, so I dont know what the problem is.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Yas
  • 11
  • 1
  • 2
    Presumably your kernel doesn't support 32-bit executables (or 32-bit system calls in 64-bit programs, so don't expect that to work either). e.g. WSL1, or a custom build of actual Linux without CONFIG_IA32_EMULATION, e.g. on Gentoo. I'm going to guess WSL1 for now; we can change the duplicate if that guess is wrong. – Peter Cordes Aug 24 '21 at 02:33
  • 3
    Oh you did mention WSL. Almost certainly you accidentally still have WSL1, not WSL2. [Does WSL 2 really support 32 bit program?](https://stackoverflow.com/q/61300194) has details about how to check / upgrade. – Peter Cordes Aug 24 '21 at 02:57
  • 2
    Also note that learning 64-bit in the first place is another option. [32-bit system calls or executables on 64bit Windows Subsystem For Linux? Or a working 64-bit Hello World?](https://stackoverflow.com/q/57915303). But then you'd need to find an x86-64 NASM tutorial; porting a 32-bit tutorial at the same time you're trying to learn the basics from it will just be confusing, because it's only simple after you understand the basics and how the pieces fit together :P. – Peter Cordes Aug 24 '21 at 03:04

0 Answers0