x86 assembly create Win32 executable NASM

2019-08-04 01:11发布

问题:

I want to create a valid Win32 executable, that can be run as standalone application.

For example, this simple program:

bits 32
mov eax,1
ret

I compiled it using NASM with

nasm test.asm -o test.exe

Then I ran that program. It started NTVDM and it told me "The NTVDM CPU encountered illegal instruction" and some technical details, probably dump, and registers.

So, I want to create a standalone Win32 application in assembly language. I don't want to create COM file, like in DOS.

回答1:

[section] .text
    global _start
_start:
    mov eax, 1
    ret

can be assembled like this:

 nasm -fwin32 file.asm              (this should give you file.obj)

and

 link /subsystem:windows /entry:start file.obj       

(or)

 ld -e _start file.obj      

whatever linker you choose should give you your .exe



回答2:

At least Windows XP refuses to load an application that does not use any DLL files. I didn't test with Windows 7 up to now!

The reason is that there are no official interfaces but the DLLs that come with Windows and that a program that has neither inputs nor outputs makes no sense.