你好世界NASM使用在Windows组件 [英] Hello world using nasm in windows assembly
问题描述
我使用 NASM 编译下面的组装。然而,在Windows下的控制台中的code崩溃。
C:\\> NASM -f win32的TEST.ASM -o test.o
C:\\> LD test.o -o test.exe的
块引用>部分。数据
味精DB世界,你好!,0AH
LEN EQU $ -msg.text段
全球_WinMain @ 16_WinMain @ 16:
MOV EDX,LEN
MOV ECX,味精
MOV EBX,1
MOV EAX,4
INT 80H MOV EBX,0
MOV EAX,1
INT 80H我不明白我在做什么错了。
根据这个帖子。在windows下的约定
主
功能不可用在Windows下,必须由的WinMain
所取代。所以,如果你的入口点是
_start
或主
,它应改为_WinMain @ 16
并修改RET
在程序结束时沤16
:通过工作示例:
.text段
全球_WinMain @ 16_WinMain @ 16:
MOV EAX,0
RET 16
解决方案最大的问题是,你要使用的Linux在Windows interupts!
诠释80不能在Windows工作。我们使用的大会,让你的入口点可以是任何你想要的标签。该标准的入口点,LD查找是_start,如果你想使用另一种标签,你需要告诉LD与-e选项
所以,如果你希望你的起始标签是主要的,那么你需要全球主要
LD -e主要test.o -o TEST.EXE如果您要使用NASM在Windows上,我会建议使用GoLink为你的连接器。
下面是一个简单的Windows控制台应用程序:STD_OUTPUT_HANDLE EQU -11
NULL EQU 0全球GobleyGook
EXTERN了ExitProcess,GetStdHandle,WriteConsoleA段.data
味精分贝的Hello World!,13,10,0
msg.len EQU $ - 味精.bss段
假RESD 1.text段
GobleyGook:
推STD_OUTPUT_HANDLE
调用GetStdHandle 推空
推假人
推msg.len
味精推
推EAX
电话WriteConsoleA 推空
调用了ExitProcess生成文件:
你好:hello.obj
GoLink.exe /控制台/进入GobleyGook hello.obj KERNEL32.DLLhello.obj:hello.asm
NASM -f win32的hello.asm -o hello.objI'm using nasm to compile the following assembly. 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
I can't see what I'm doing wrong.
According to this post. Under the windows the convention the
main
function is not available under Windows and must be replaced byWinMain
.So if your entry point is
_start
ormain
, it should be changed to_WinMain@16
and change theret
at the end of the procedure toret 16
:By working example:
section .text global _WinMain@16 _WinMain@16: mov eax, 0 ret 16
解决方案The biggest problem is that you are trying to use Linux interupts on windows! int 80 will NOT work on windows.
We are using Assembly, so your entry point can be ANY label you want. The standard entry point that ld looks for is _start, if you want to use another label, you need to tell ld with the -e option So if you want your start label to be main, then you need
global main ld -e main test.o -o test.exe
If you are going to use NASM on Windows, I will recommend using GoLink as your linker. Here is a simple windows console app:
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
这篇关于你好世界NASM使用在Windows组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!