Solved:
Hi all
Im working on a program thats supposed to take a character the user inputs; and to print it in 100 random positions in the screen.
QuoteWrite a program that displays a single character at 100 random screen locations, using a timing delay of 100 milliseconds between locations.
Hint: Use the GetMaxXY procedure to determine the current size of the console window.
<<its a question from Kip Irvine's assembly language book.
I had the GetMaxXY and, randomize parts working, but the Gotoxy is seemingly not working. I was assuming that once i get the value from the user; i would use the GetMaxXY function to find the size of the page; and then use the randomize functions to generate random x,y coordinates that fall within this page and then use the Gotoxy function to point my curser to that location and print out the character .
but my program prints the character only in the first position of each line.....im not able to find out why this is happening. ill be really grateful if anyone can help me solve this problem. thanks! :)
[/s]
INCLUDE Irvine32.inc
MAX_COUNT = 100
.data
str1 BYTE "Enter a character: ",0
char BYTE ?
rows BYTE ?
cols BYTE ?
randrow WORD ?
randcol WORD ?
.code
main PROC
mov edx, OFFSET str1
call writeString
call ReadChar
mov char, al
call crlf
call WriteChar
call crlf
mov eax,0
mov ebx,0
mov ecx,0
mov edx,0
call crlf
call GetMaxXY
mov rows,dh
mov cols,dl
call crlf
call crlf
movzx eax,rows
call WriteDec
call crlf
call crlf
movzx eax,cols
call WriteDec
call crlf
mov eax,0
mov ebx,0
mov ecx,0
mov edx,0
;creating random numbers
mov ecx,MAX_COUNT ;counter
L1:
movzx eax,rows
call RandomRange
;call WriteDec
call crlf
mov eax,0
movzx eax,cols
call RandomRange
;call WriteDec
call crlf
mov eax,0
mov ebx,0
mov edx,0
mov dh,rows
mov dl, cols
call Gotoxy
movzx eax,char
call WriteChar
call crlf
mov eax,0
loop L1
exit ;exiting main.
main ENDP
END main
Ah! I got it working. I was using rows. cols instead of the randrow, randcol values which held the generated random numbers :red
PS: is there a way to initialize all teh registers to 0 without manually typing
mov eax,0
mov ebx,0
mov ecx,0
etc
etc ?
the working code is here
INCLUDE Irvine32.inc
MAX_COUNT = 100
.data
str1 BYTE "Enter a character: ",0
char BYTE ?
rows BYTE ?
cols BYTE ?
randrow BYTE ?
randcol BYTE ?
.code
main PROC
mov edx, OFFSET str1
call writeString
call ReadChar
mov char, al
call crlf
call WriteChar
call crlf
mov eax,0
mov ebx,0
mov ecx,0
mov edx,0
call crlf
call GetMaxXY
mov rows,dh
mov cols,dl
call crlf
call crlf
mov eax,0
mov ebx,0
mov ecx,0
mov edx,0
;creating random numbers
mov ecx,MAX_COUNT ;counter
L1:
movzx eax,rows
call RandomRange
mov randrow, al
;call WriteDec
call crlf
mov eax,0
movzx eax,cols
call RandomRange
mov randcol, al
;call WriteDec
call crlf
mov eax,0
mov ebx,0
mov edx,0
mov dh,randrow
mov dl,randcol
call Gotoxy
movzx eax,char
call WriteChar
call crlf
mov eax,0
loop L1
exit ;exiting main.
main ENDP
END main
here is the result
Quote
Enter a character: g
g g g g
g g
g
gg g g
g
g g g g
g g g g
g
g g g g g gg
g g
g
g g
g g
g
g g
g g g g g
g
g
g g g
g g g
Press any key to continue . . .
g g gg
g g g g
g g g
g g
g g
g g
g
g g gg
g
g g g
g
g g
g
g g g
g g g
g
g
g g g g
g g g g g