以下程序的要点是用每种背景和前景色的组合打印出字母“c”。Irvine's WriteString的奇怪输出
在我使用的颜色库中定义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 . . .
谁能告诉我为什么发生这种情况?
我没有看到一个'.model'指令,你也不会递增/递减循环的任何计数器。你有没有遗漏代码示例? – slugster 2010-09-27 03:33:25
@slugster:循环指令递减[E] CX,将结果与0进行比较,如果它不为零,则跳转到指定的标签。据猜测,他使用的包含文件设置了内存模型。 – 2010-09-27 03:40:39
是的,这是正确的。 irvine图书馆为我们贬低它。它是计算机体系结构课程,而不是MASM课程。 – 2010-09-27 15:00:55