通过 MASM 调用 printf

Calling printf by MASM

我正在尝试探索汇编的世界 :) 但由于某种原因,它不起作用 :( 它编译,但在 运行,它什么也不打印 :(

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\msvcrt.lib ; Some default includes :P

printf proto C :vararg

.data
Text       db "Hello World",0

.code
start:
mov eax, offset Text
push eax ; Push text to the stack
call printf 
pop eax ; Pop text from the stack
push 0 ; Exit code 0 (Success)
call ExitProcess
end start

您需要 link 和 /SUBSYSTEM:CONSOLE,您当前的代码才能打印任何内容。

来自 the documentation SUBSYSTEM:

WINDOWS
Application does not require a console, probably because it creates its own windows for interaction with the user.

CONSOLE
Win32 character-mode application. The operating system provides a console for console applications.