Original Post
I've recently been working on a little bit of assembly programming, using the Masm assembler, and decided to try a little program in mode 13h. I wanted it to draw alternating black and white squares in a tile-like pattern. Well, I got the code to work, but everytime I assemble it, it gives me a random line that is all black. Here is the source code:
.MODEL SMALL
.STACK
.DATA
x dw 0
y dw 0
go dw 0
.CODE
MAIN PROC
mov ax,13h ;This sets the screen into mode 13h
int 10h
;########################
;color = white
mov cx, 25
program:
mov go,0
push cx
mov cx,4
line:
push cx
mov cx,40
top:
push cx
mov cx,4
white:
mov ah, 0Ch ;Draws a dot in the middle of the screen
mov al, 31 ;Sets color
mov di, 0A000h ;draw the pixel
mov es, di
push ax
mov ax, 320
mul y
mov di, ax
pop ax
add di, x
mov es:[di], al ;done drawing the pixel
inc x
loop white
mov cx,4
black:
mov ah, 0Ch ;Draws a dot in the middle of the screen
mov al, 16 ;Sets color
mov di, 0A000h ;draw the pixel
mov es, di
push ax
mov ax, 320
mul y
mov di, ax
pop ax
add di, x
mov es:[di], al
inc x
loop black
pop cx
loop top
mov x,0
pop cx
inc y
loop line
program1:
cmp go,1
je program
mov cx,4
line1:
push cx
mov cx,40
bottom:
push cx
mov cx, 4
black1:
mov ah, 0Ch ;Draws a dot in the middle of the screen
mov al, 16 ;Sets color
mov di, 0A000h ;draw the pixel
mov es, di
push ax
mov ax, 320
mul y
mov di, ax
pop ax
add di, x
mov es:[di], al
inc x
loop black1
mov cx,4
white1:
mov ah, 0Ch ;Draws a dot in the middle of the screen
mov al, 31 ;Sets color
mov di, 0A000h ;draw the pixel
mov es, di
push ax
mov ax, 320
mul y
mov di, ax
pop ax
add di, x
mov es:[di], al
inc x
loop white1
pop cx
loop bottom
mov x,0
pop cx
inc y
loop line1
pop cx
mov go,1
loop program1
;///////////////////////////////////////////////////////
mov ah,07h ;Waits for a key press
int 21h
mov ax,03h ;Sets the screen back to text mode
int 10h
mov ax,4c00h ;exit (no error)
int 21h
MAIN ENDP
END MAIN
So, I have two questions: Why does it give me the random black line? and The assembler gave me an error when I looped from the bottom all the way up to the top, it said the distance was too far. Why would this be and is there any way to fix that other than what I did (set it to jump to another point in the middle of the program, then to the top)? Any help is greatly appreciated!
[edited by - eriel on August 5, 2003 6:16:00 PM]