Star Dev
Star Dev

Reputation: 43

Compile assembly (NASM with int 80h system calls) in windows

I am learning to code assembly (NASM). But i have problem, i am coding online but i want to convert this code below to exe and run it. (By clicking double click on it, not in cmd). And i dont have a clue how to do it. i know i must use a nasm from https:://www.nasm.us and a linker. For the linker i want to use ld from mingw. but i dont know how to do it. i didnt find any thing on the internet

section .data
msg: db "Eneter your name : ", 10
msg_l: equ $-msg

hello: db "Hello, "
hello_l: equ $-hello

section .bss
name: resb 255

section .text
global _start:

_start:

mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_l
int 80h

mov eax, 3
mov ebx, 0
mov ecx, name
mov edx, 255
int 80h

mov eax, 4
mov ebx, 1
mov ecx, hello
mov edx, hello_l
int 80h

mov eax, 4
mov ebx, 1
mov ecx, name
mov edx, 255
int 80h

mov eax, 1
mov ebx, 0
int 80h

Upvotes: 0

Views: 857

Answers (1)

raven_lee
raven_lee

Reputation: 30

The best way to work with linux in windows is to use wsl2. The windows subsystem will allow you to use real linux system calls. There is a learning curve but its worth it.

  1. Follow a guide on how to install ws2.
  2. Go to the windows store and download one of the few linux terminals. I use ubuntu.
  3. Install gcc in the terminal so that you will have a gnu compiler, gnu assembler, and the gnu linker(ld).
  4. Install nasm in the terminal. Not the windows app version.

After everything is set up, you can get a nice workflow going.

  1. you would open the terminal.
  2. change directories which will get you into the c drive: cd /mnt/c
  3. create a folder in the c drive where you want to do your work
  4. change directories to that folder: cd foldername
  5. create a nasm asm file and put some code into it.
  6. then you can use nasm to assemble, ld to link, execute

When you assemble with nasm you can now use elf:

nasm -f elf32 main.asm

ld -m elf_i386 main.o -o main

./main

or:

nasm -f elf64 main.asm

ld main.o -o main

./main

Upvotes: 2

Related Questions