简体   繁体   中英

x86 assembly create Win32 executable NASM

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.

[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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM