Katido 622
Katido 622

Reputation: 21

NASM in SASM crashing in windows

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.

Upvotes: 1

Views: 1347

Answers (1)

TravorLZH
TravorLZH

Reputation: 302

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

Upvotes: 1

Related Questions