1

I'm trying to run some NASM code inside of SASM IDE. When I try it, Windows 10 just makes it crash.

%include "io.inc"

section .data
msg db 'Hello, world!',10  ;string to be printed
len equ $ - msg     ;length of the string


section .text
   global main     ;must be declared for linker (ld)

main:               ;tells linker entry point
   mov  edx,len     ;message length
   mov  ecx,msg     ;message to write
   mov  ebx,1       ;file descriptor (stdout)
   mov  eax,4       ;system call number (sys_write)
   int  0x80        ;call kernel

   mov  eax,1       ;system call number (sys_exit)
   int  0x80        ;call kernel
   ret

This just makes windows crash the program. (Sorry for the image) Image

When I try to run it.. well.. that's what happens.

rkhb
  • 14,159
  • 7
  • 32
  • 60
Katido 622
  • 21
  • 1
  • 7

1 Answers1

1

It is not good to practice NASM on Windows because Windows does not provide any Linux System calls like sys_write. Instead, you need to run it on Linux (for Windows 10 users, you may use WSL). For Windows, you have to link it with a C library.

Here's a NASM program that works with C library on Windows

[global _main]
[global _printf]
str db  "Hello world!",0xA,0   ; Don't forget the null-terminator
_main:
        push str
        call _printf
        add  esp,4
        ret
TravorLZH
  • 302
  • 1
  • 9
  • What is WSL? I am on Windows 10. – Katido 622 Apr 30 '18 at 19:16
  • @Katido622: WSL (Windows Subsystem for Linux) is a feature on Windows 10 that allows you to run Linux on Windows. You can read more [here](https://learn.microsoft.com/en-us/windows/wsl/install-win10) – TravorLZH Apr 30 '18 at 22:14
  • @Katido622: NASM can be installed on WSL via the following command: `sudo apt-get install nasm`. Your program will run fine on Linux without modifications – TravorLZH Apr 30 '18 at 22:16
  • Note that WSL1 doesn't support 32-bit executables, or 32-bit `int 0x80` system calls in 64-bit processes. ([What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?](https://stackoverflow.com/q/46087730)). [Does WSL 2 really support 32 bit program?](https://stackoverflow.com/q/61300194) – Peter Cordes Aug 18 '21 at 11:58