Can I install nasm and run .asm codes on Windows Subsystem Linux(WSL) for Ubuntu terminal on windows?

I've been avoiding to dual boot my new Laptop to use Ubuntu yet, and I've got some assembly codes to be run in the nasm. I recently stumbled upon this Ubuntu terminal for Windows, so my question is: can I install the nasm package and run .asm codes in this terminal?

Edit: The .asm code is being compiled (I wrote the "Hello World" code as a test) with the following steps:

  1. nasm -f elf64 filename.asm
  2. ld -o filename filename.o
  3. ./filename

There is no output on the terminal, as it should display Hello World.

Here's the code for reference:

section .data
msg db "Hello World"
msglen equ $-msg
section .text
global _start
_start: mov rax,1 mov rdi,1 mov rsi,msg mov rdx,msglen
mov rax,60
mov rdx,0
syscall
4

1 Answer

You skipped a syscall in your code!

The syscall in the last line is used to exit the program. However, to display the string, you have to make another syscall after you fill the rax, rdi, rsi, and rdx registers.

The correct code is given below:

section .data
msg db "Hello World", 10
msglen equ $-msg
section .text
global _start
_start:
mov rax,1
mov rdi,1
mov rsi,msg
mov rdx,msglen
syscall
mov rax,60
mov rdx,0
syscall

I have also added a "new line" (ASCII decimal code 10) to the end of your string, so that a new line is displayed after Hello World string.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like