Irvine 的 WriteString 的奇怪输出
以下程序的重点是打印出字母“c”以及每种背景和前景色的组合。
在库中,我使用的颜色定义为 0-15 并使用以下代码:
mov eax,FOREGROUND + (BACKGROUND * 16)
call SetTextColor
这是我的代码:
INCLUDE Irvine32.inc
.data
character BYTE "c"
count DWORD ?
background DWORD 0
.code
main PROC
call Clrscr
mov ecx, 15 ; our main counter 0-15 colors
L1:
mov count, ecx ; store our outer loop counter
mov ecx, 15 ; set out inner loop counter
L2:
; since our color is defined like so... mov eax,FOREGROUND + (BACKGROUND * 16)
mov eax, count ; setup our foreground color
add eax, background ; setup our background color
call SetTextColor
; instead of multiplying each background color by 16, we are going to
; add 16 each time.
add background, 16
; print the character
mov edx, OFFSET character
call WriteString
loop L2
mov ecx, count ; reset our outside loop
loop L1
call Crlf
exit
main ENDP
END main
现在,我使用的是 Windows 7,上面的代码“有效”,但由于某种原因,它会转到某个点,程序停止,计算机开始发出蜂鸣声。另外,在程序中的某个时刻,它开始打印带有字母 c.. 的随机字符。这是我的输出:
c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c
c
c
c
c
c
c
c
c
c
c
c
c
c
c
c c c c c c c c c c
c c c c c cccccccccccccccc♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c
♠c♠c♠c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♥c♥c♥c♥c♥c♥c♥c
♥c♥c♥c♥c♥c♥c♥c♥c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺
Press any key to continue . . .
谁能告诉我为什么会发生这种情况?
the point of the following program is to print out the letter "c" with the combination of every background and foreground color.
In the library I'm using the colors are defined 0-15 and with the following code:
mov eax,FOREGROUND + (BACKGROUND * 16)
call SetTextColor
Here is my code:
INCLUDE Irvine32.inc
.data
character BYTE "c"
count DWORD ?
background DWORD 0
.code
main PROC
call Clrscr
mov ecx, 15 ; our main counter 0-15 colors
L1:
mov count, ecx ; store our outer loop counter
mov ecx, 15 ; set out inner loop counter
L2:
; since our color is defined like so... mov eax,FOREGROUND + (BACKGROUND * 16)
mov eax, count ; setup our foreground color
add eax, background ; setup our background color
call SetTextColor
; instead of multiplying each background color by 16, we are going to
; add 16 each time.
add background, 16
; print the character
mov edx, OFFSET character
call WriteString
loop L2
mov ecx, count ; reset our outside loop
loop L1
call Crlf
exit
main ENDP
END main
Now, I'm using windows 7, the above code "works" but for some reason, it goes to a certain point, the program stops, and the computer starts beeping. Also, at a certain point in the program, it starts printing random characters with the letter c.. here is my output:
c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c
c
c
c
c
c
c
c
c
c
c
c
c
c
c
c c c c c c c c c c
c c c c c cccccccccccccccc♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c
♠c♠c♠c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♥c♥c♥c♥c♥c♥c♥c
♥c♥c♥c♥c♥c♥c♥c♥c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺
Press any key to continue . . .
Can anyone tell me why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Irvine 的 WriteString 需要一个“null-终止字符串”。有些人可以此处 (IrvineLibHelp.exe) 下载 CHM 文件形式的帮助。
说“EDX = 指向字符串”有点草率。 EDX 只是指向可通过标签(此处:“字符”)识别的内存地址。
WriteString
将从该位置逐字节获取并将其写入字符或控制指令,无论其真实类型或意图如何,直到遇到值为 0 的字节。MASM 没有定义字符串的指令最后一个 0,因此必须手动添加:打印字符的另一种方法是使用 WriteChar:
Irvine's WriteString needs a "null-terminated string". Some can download the help as CHM-file here (IrvineLibHelp.exe).
It's a little bit sloppy to say "EDX = points to string". EDX just points to an memory address identifiable by a label (here: "character").
WriteString
will get byte for byte from that location and write it as character or control directive regardless of his real type or intention until it comes across a byte with the value 0. MASM has no directive to define a string with the last 0, so it has to be added manually:An alternative way to print a character is to use WriteChar:
应该是:
Should be:
WriteString 的作用是什么?如果函数打印字符串可能需要以$结尾“character BYTE "c"”(如果是DOS程序.09函数Int21h)
What does WriteString do? If the function prints a string may be you need to end "character BYTE "c" " with $ (if it is DOS program. 09 function Int21h)