Hello world using nasm in windows build

I use nasm to compile the next build. However, the code crashes in the console under Windows.

C: \> nasm -f win32 test.asm -o test.o

C: \> ld test.o -o test.exe

section .data
  msg   db    'Hello world!', 0AH
  len   equ   $-msg

section .text
  global _WinMain@16

_WinMain@16:
  mov   edx, len
  mov   ecx, msg
  mov   ebx, 1
  mov   eax, 4
  int   80h

  mov   ebx, 0
  mov   eax, 1
  int   80h

According to this post . The function is mainnot available under Windows and should be replaced by WinMain.

So, if your entry point _startor main, it should be changed to _WinMain@16and changed retat the end of the procedure to ret 16:

My working example:

section .text       
 global _WinMain@16       

_WinMain@16:       
 mov eax, 0       
 ret 16 
+5
source share
2 answers

The biggest problem is that you are trying to use Linux interrupts on Windows! int 80 will not work with windows.

Assembly, , . , ld, _start, , ld -e , , ,

global main
ld -e main test.o -o test.exe

NASM Windows, GoLink . Windows:

STD_OUTPUT_HANDLE   equ -11
NULL                equ 0

global GobleyGook
extern ExitProcess, GetStdHandle, WriteConsoleA

section .data
msg                 db "Hello World!", 13, 10, 0
msg.len             equ $ - msg

section .bss
dummy               resd 1

section .text
GobleyGook:
    push    STD_OUTPUT_HANDLE
    call    GetStdHandle

    push    NULL
    push    dummy
    push    msg.len
    push    msg
    push    eax
    call    WriteConsoleA 

    push    NULL
    call    ExitProcess

Makefile:

hello: hello.obj
    GoLink.exe  /console /entry GobleyGook hello.obj kernel32.dll  

hello.obj: hello.asm
    nasm -f win32 hello.asm -o hello.obj
+21

, , , WINE Linux, .:)

WINE Linux Windows PE; , WINE DLL-.

+5

All Articles