下面程序的重点是打印出字母“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 . . .
谁能告诉我为什么会这样?