|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- ; 使用 Win32ASM 写的 Hello, world 程序
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 使用 nmake 或下列命令进行编译和链接:
- ; ml /c /coff Hello.asm
- ; Link /subsystem:windows Hello.obj
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .386
- .model flat,stdcall
- option casemap:none
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; Include 文件定义
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- include \masm32\include\windows.inc
- include \masm32\include\user32.inc
- includelib \masm32\lib\user32.lib
- include \masm32\include\kernel32.inc
- includelib \masm32\lib\kernel32.lib
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 数据段
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .data
- szCaption db '来自鱼C工作室', 0
- szText db 'Hello, World !', 0
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 代码段
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .code
- start:
- invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK
- invoke ExitProcess,NULL
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- end start
复制代码
如图:编译链接之后,执行时中文是乱码 ?
这是因为在代码中使用了中文字符,而编译器默认使用的字符集与系统默认字符集不一致导致的。解决方法是在代码开头添加以下语句:
- .586
- .model flat, stdcall
- option casemap:none
- include \masm32\include\windows.inc
- include \masm32\include\user32.inc
- includelib \masm32\lib\user32.lib
- include \masm32\include\kernel32.inc
- includelib \masm32\lib\kernel32.lib
- .code
- start:
- sub esp, 8
- push 0
- push offset szCaption
- push offset szText
- push 0
- call MessageBoxW
- add esp, 16
- push 0
- call ExitProcess
- end start
复制代码
在代码中使用 MessageBoxW 而不是 MessageBox ,并将 szCaption 和 szText 的类型从 db 改为 dw ,同时在字符串前添加 L 来表示它们是 Unicode 字符串。这样就可以正确地显示中文字符了。
|
-
|