我正在尝试扩展此程序并允许用户使用寄存器输入要放入矩阵的字符。无论输入如何,AL都会返回笑脸。我需要做些什么来使我能够在L2内使用更大的寄存器,即移动al,bufSize使用的寄存器太小。
我还有一个问题,可以将标签作为另一个程序内的跳转指令的目标
使用跳转指令如何编写它以仅使用一个循环?
所以在我的新代码中我使用了一个跳转指令而不是一个循环,但是当我在调试器中观察它时,它会让我想起很多循环,它是一回事吗?
TITLE Color Matrix
(ClrMatrix.asm)
Comment !
Displays an Character in all possible colors
!
INCLUDE Irvine32.inc
BUFFMAX = 128
.data
charPrompt BYTE "Choose a letter: ",0
buffer BYTE BUFFMAX+1 DUP(0)
bufSize BYTE ?
.code
main PROC
call ChooseCharacter
call GenerateMatrix
main ENDP
ChooseCharacter PROC
pushad
mov edx,OFFSET charPrompt
call WriteString
mov ecx,BUFFMAX
mov edx,OFFSET buffer
call ReadString
mov bufSize,al
call Crlf
popad
ret
ChooseCharacter ENDP
GenerateMatrix PROC
call Clrscr
mov eax,0
mov ecx,16
L1: push ecx ; vary the background colors
mov ecx,16
L2: call SetTextColor ; vary the foreground colors
push eax
mov al,bufSize
call WriteChar
pop eax
inc al ; next foreground color
loop L2
sub al,16 ; reset foreground color to zero
add al,16 ; select next background color
call Crlf
pop ecx
loop L1
mov eax,7
call SetTextColor
exit
GenerateMatrix ENDP
END main
答案 0 :(得分:0)
工作代码:
TITLE Q16 Color Matrix (ClrMatrix.asm)
Comment !
Author: Louis Krueger
date:4/17/2014
Displays a defined Character in all possible colors
!
INCLUDE Irvine32.inc
.data
charPrompt BYTE "Choose a letter: ",0
Character DWORD ?
.code
;========================================================
main PROC ;Calls the procedures
;========================================================
call ChooseCharacter
call GenerateMatrix
main ENDP
;-----------------------------------------------------------------
ChooseCharacter PROC
;Takes user input character to use as charcter in print
;-----------------------------------------------------------------
mov edx,OFFSET charPrompt
call WriteString
call ReadChar
mov Character,eax
call Crlf
ret
ChooseCharacter ENDP
;-------------------------------------------------------------------
GenerateMatrix PROC
;-------------------------------------------------------------------
call Clrscr
mov eax,0
mov ecx,16
L1: push ecx ; loop for background colors
mov ecx,16
L2: call SetTextColor ; nested loop for foreground colors
push eax
mov eax,Character
call WriteChar
pop eax
inc al ; inc the foreground color
loop L2
sub al,16 ; resets the forground for next iteration
add al,16 ; goes to the next background color
call Crlf
pop ecx
loop L1
mov eax,7
call SetTextColor
exit
GenerateMatrix ENDP
END main