I Am trying to expand on this program and allow the user to input the character to put in the matrix, using the register. AL returns a smiley face regardless of input. What do I need to do to make it so I can use larger register inside of L2, the mov al,bufSize uses too small of a register.
I also have a question regard labels that can be a target of a jump instruction inside of another procedure
Using jump instructions how can I write this to use only one loop?
So in my new code i use a jump instruction instead of a loop, but when i watch it in the debugger it reminds me alot of a loop, is it the same thing?
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
Working code:
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