ASM程序中如需输出中文,需将中文字符转化为对应的Unicode码,并通过Windows API进行输出。以下代码为在MASM中使用MessageBoxW函数输出中文字符的示例:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
Greetings db "你好,世界!",0
.code
start:
push 0 ;将参数0传递给MessageBoxW函数
push offset Greetings ;将要输出的中文字符串地址压入栈中
push offset GreetingsCaption ;将弹出窗口标题地址压入栈中
push 0 ;将第四个参数设为MB_OK(只包含一个确定按钮)
call MessageBoxW ;调用MessageBoxW函数输出中文字符串
invoke ExitProcess, 0 ;退出程序
end start
以上代码通过将中文字符串的内存地址压入栈中,并调用Windows API中的MessageBoxW函数实现中文字符的输出。
上一篇:asm代码无法返回正确结果。
下一篇:ASM调用C++