0

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
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Star Dev
  • 59
  • 4
  • 2
    Windows doesn't support `int 80h`.. – xiver77 Jul 09 '22 at 14:09
  • You can fix your program to make it run on Windows, and it will run with a double click, but note that double clicking a console program will make it run and close immediately as it finishes. – xiver77 Jul 09 '22 at 14:13
  • If you don't know how to use a linker, I think you need better understanding on how a binary executable file is made and run on a modern operating system, before you do more assembly coding. It's basically the same way you'd link compiled object files to an executable, but for a pure assembly program, you also have to define the program entry point yourself. – xiver77 Jul 09 '22 at 14:18
  • [Here](https://stackoverflow.com/a/1029093) is an example NASM program for 32-bit Windows that you might find interesting. The example uses `link.exe`, but you can replace that with `ld` from MinGW. – xiver77 Jul 09 '22 at 14:31
  • Note that assembly is *assembled,* not *compiled.*. The tool to do that is called an *assembler,* not a *compiler.* – fuz Jul 09 '22 at 16:12

1 Answers1

2

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
raven_lee
  • 48
  • 7