汇编控制台程序如何换行?
本帖最后由 Armboy2010 于 2015-2-3 16:27 编辑初学汇编,简单写了个循环,输出发现竟然换不了行,有碰到过此问题的盆友吗?{:soso_e103:}
我的环境VS2010+WIN7 64+MASM32
代码如下:
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include msvcrt.inc
includelib msvcrt.lib
include masm32.inc
includelib masm32.lib
.data
n dd 1
msg db 'n=%d \n \r\n', 0
szLine db '\n \r\n', 0
.code
MyLoop proc
start:
cmp n, 101
jae EndLoop
; printf("n=%d \r\n", n);
invoke crt_printf, addr msg, n ; 换不了行?
invoke StdOut, addr szLine ; 换不了行?
inc n
jmp start
EndLoop:
ret
MyLoop endp
.code
start:
invokeMyLoop
invokecrt_getchar
invokeExitProcess, NULL
end start
本帖最后由 theend 于 2015-2-3 18:06 编辑
.data
msg db 'n=%d \n \r\n', 0
szLine db '\n \r\n', 0
.data是数据段,db "xxxxxx"或'xxxx'符号里定义的只是字符串,你本意是想表达C的\n \r 转义字符结果。
其实只是一个变量字符串。{:soso_e104:}
在C语言中使用\n\r来完成回车换行。
Win32汇编中使用数据0dh,0ah
例如:
.data
inform db 'Hello',0dh,0ah,'World!',0
szTitle db 'Title Name',0
...
.code
...
invoke MessageBox,NULL,offset inform,addr szTitle,0
...
会在弹出窗口(窗口标题为Title Name)中显示:
Hello
World!
转自网上,可行性楼主自行验证,我没有编译环境,哈哈
{:soso_e127:} 13, 10
.data
pyg db "www.", "chinapyg", ".com", 13, 10, "piaoyun",0
.code
start:
invokeMessageBox,HWND_DESKTOP,pyg,invoke GetCommandLine,MB_OK
invokeExitProcess,0
.end start
飘云 发表于 2015-2-3 18:08
13, 10
哈哈,看来我回答对了,飘总加点分分吧{:soso_e113:}
theend 发表于 2015-2-3 18:11
哈哈,看来我回答对了,飘总加点分分吧
感谢各位的热心帮助,我试了下,终于可以换行了{:soso_e195:}
最终代码如下:
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include msvcrt.inc
includelib msvcrt.lib
include masm32.inc
includelib masm32.lib
.data
n dd 1
msg db 'n=%d', 13, 10, 0
.code
MyLoop proc
start:
cmp n, 101
jae EndLoop
; printf("n=%d \r\n", n);
invoke crt_printf, addr msg, n
inc n
jmp start
EndLoop:
ret
MyLoop endp
.code
start:
invokeMyLoop
invokecrt_getchar
invokeExitProcess, NULL
end start
页:
[1]