Reputation: 159
I'm trying to set up an Assembly Programming Environment on Windows. I do have Linux installed, but for curiosity sake, and also studying purposes for learning WSL, I'm trying to make it run through WSL2 on Windows 10.
I've tried to setup both Alpine and Ubuntu (base) installing only the following tools:
bash bash-doc bash-completion
util-linux pciutils usbutils coreutils binutils findutils grep
It was installed with either apk add
or apt install
.
Then I've wrote the following example from Programming Ground Up:
.section .data
.section .text
.globl _start
_start:
movl $1, %eax
movl $0, %ebx
int $0x80
I did the compilation and link without any fancy flags, just the minimum like in the book example.
as exit.s -o exit.o
ld exit.o -o exit
I know that those calls like int $0x80
depends on architecture, operation system, etc.
It's returning Segmentation fault
when I try to run it on the WSL image.
Searching around I've got to know that Segmentation fault is probably regarding the program not exiting the execution, like when a section doesn't have a ret
statement.
(In this case, int $0x80
should be enough for activating the kernel and returning/exiting by calling the value 1 set on ax register)
I thought it was because I'm trying to compile and run a 32bit ASM code in a 64bit machine. But, I did a ssh connection to a pub unix server, which is also a Ubuntu x86_64, and the same code could run without any problem.
Is it a WSL2 limitation? Or do this pubnix have something installed or configured for it to accept the 32bit code without any additional flag?
Upvotes: 0
Views: 1398
Reputation: 159
The WSL2 do have support to 32-bit libraries and system calls.
So it's a nice way of programming assembly on Windows without the need for dual-boot and assembly emulators.
But it is a mistake to assume that since WSL2 is installed, it's also being used.
If you already have WSL2 installed, you can either convert a WSL1 image to WSL2, or set the WSL version to the version you want (WSL2) to be used when creating/importing your next image.
(In my case, Docker Desktop for Windows automatically installed WSL2 for me)
wsl -l -v
wsl --set-default-version 2
Everytime you create a new image or import, it will be set as WSL2.
If you want to go back to WSL1 you can wsl --set-default-version 1
.
Now you can create a new image as usual.
wsl --set-version image_name 2
(Converting an image may take a long time)
wsl --export current-image image-backup.tar
mkdir new-folder
wsl --import newimg new-folder image-backup.tar
(Exporting and Importing will keep your $HOME and files, it's like making a backup of the entire image)
Upvotes: 2