通过MASM调用printf

问题描述

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

.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

解决方法

您需要与/SUBSYSTEM:CONSOLE链接以使用当前代码来打印任何内容。

the documentationSUBSYSTEM

WINDOWS
应用程序不需要控制台,可能是因为它创建了自己的窗口来与用户交互。

CONSOLE
Win32字符模式应用程序。操作系统为控制台应用程序提供了一个控制台。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...