1
votes

i am using windows 7 for learning assembly language.I am using NASM for creating object files and mingw for creating executable files.

i am using the following commands for compile and run executable files

del hello.o
del hello.exe
nasm -f elf hello.asm
ld hello.o -o hello.exe
hello

while running the hello.exe file,an error message showing "hello.exe has stoped working"

while using the following command

    nasm -f bin hello.asm -o program.exe

i have got an error shown below

enter image description here

my program code

global _start            ; global entry point export for ld
section .text
_start:
; sys_write(stdout, message, length)
mov eax, 4        ; sys_write syscall
mov ebx, 1        ; stdout
mov ecx, message    ; message address
mov edx, length        ; message string length
int 80h
; sys_exit(return_code)
mov eax, 1        ; sys_exit syscall
mov ebx, 0        ; return 0 (success)
int 80h
section .data
message: db 'Hello, world!',0x0A    ; message and newline
length: equ $-message            ; NASM definition pseudo-instruction
2

2 Answers

3
votes

What you have there is Linux code (int 0x80, sys_write and sys_exit being kernel system calls for rather low-level stuff).

I'm not convinced it's a good idea to try and call the Linux kernel when you're running on the Windows operating system. That's unlikely to end well :-)

MinGW is minimalist GNU for Windows, a way of using the gcc toolchain for writing Windows applications. You have to therefore follow the Windows rules.

2
votes

Besides your code calling the linux kernel, as paxdiablo pointed out, you have assembled it to flat-form binary, which will not run under windows. You need to use nasm -f win32.