Skip to content

Instantly share code, notes, and snippets.

@herbetom
Created May 15, 2018 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save herbetom/b999ef0b7ace022e1b51f972f8dd29f1 to your computer and use it in GitHub Desktop.
Save herbetom/b999ef0b7ace022e1b51f972f8dd29f1 to your computer and use it in GitHub Desktop.
HOWTO Run 32 Bit Assembler within the WSL (Windows Subsystem for Linux)

HOWTO Run 32 Bit Assembler within WSL (Windows Subsystem for Linux)

Running a 32bit Binary within WSL can be complicated, because at the moment WSL only runs ELF-64 binaries.

Installation of WSL is described here (docs.microsoft.com)

sudo apt update
sudo apt upgrade
apt install build-essential gcc-multilib

# WSL currently only works on x64 systems, and only runs ELF-64 binaries.
# (https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13377507-please-add-32-bit-elf-support-to-the-kernel)
# so the following must be done:
# (Source: https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520)

sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'
sudo service binfmt-support start
dpkg --add-architecture i386
apt update

To run an IA-32 Assembler Programm you have to create a file containing the Programm with the file extension *.s

Tip: within WSL you can find under /mnt/c/ your local drive so you can create and edit the Assembler file within your favorite Editor within Windows.

Then maybe you need to start the following sudo service binfmt-support start

After that you can compile your code with gcc –m32 –o example example.s

Now you should be able to run your code with ./example


Tested on Ubuntu 16.04 but should also work with later Versions of Ubuntu. Should also work with Debian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment