0

I use NASM as an Assembler, I'm trying to learn Assembly Language after C++, and I'm facing too much problems like after generating .OBJ with the Command nasm -f win32 c:\asm\assembly.asm this generates a assembly.obj file, and after using a command in CMD link c:\asm\assembly.obj /OUT:c:\asm\assembly.exe /SUBSYSTEM:CONSOLE /ENTRY:start this generates a assembly.exe file.

But if I try to open it, Windows displays a box saying "The Program has stopped working" Whats it?? I'm very confused, and I'm aware of the IDEs in the Internet, but don't want to use any of them, I like the command prompt window, but never used it for linking any of my Applications(c++), And this is the Code copied from TutorialsPoint.com:

NOTE*: All Comments are Orignal as on the TutorialsPoint's Website, it is'nt mine...

section .text
    global _start   ;must be declared for linker (ld)
_start:             ;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

section .data
msg db 'Hello, world!', 0xa  ;our dear string
len equ $ - msg              ;length of our dear string

I tried changing _start to _WinMain@16 as on a Website(Windows Programs uses _WinMain instead _start on linux) but it gives Linker error:Unresolved Externals, But this code Assembled and linked fine, the Only problem i faced is that the Applications get hanged or they Stoped working.

Thanx in Advance!!

Community
  • 1
  • 1
  • The code you're assembling is written for an x86 Linux system. That's not going to work in Windows. – Michael Jan 10 '15 at 17:47

1 Answers1

1

It crashes because you're trying to run assembly made for Linux on Windows. Here your code is trying to call some of the Linux kernel's syscalls to write a Hello World and exit, but this can't work on Windows. Assembly is rarely multi-platform.

As a rule of thumb, if you see int 0x80 chances are that this code will not work on Windows.

Instead on Windows you can try calling the MessageBox function in kernel32.dll for example to display your HelloWorld, see this post if you need some help with this.

Community
  • 1
  • 1
tux3
  • 7,171
  • 6
  • 39
  • 51