Archived

This topic is now archived and is closed to further replies.

eriel

Assembly Problem

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Your first problem... i cut/paste code and compiled it with TASM (not MASM.. i dont have it )and everything looks fine for me.

Next think, TASM have directive called JUMPS, it allows to make jumps biger then -128/127 bytes long.
Look to manual for somethink like this for MASM it have to have it.




Share this post


Link to post
Share on other sites
So it is working fine on the TASM assembler? That''s interesting. Thanks for the advice on the long jump command. I was wondering, what version of TASM do you have?

Share this post


Link to post
Share on other sites
It is TASM v4.0



"The Gods Made Heavy Metal And They Saw That It Was Good
They Said To Play It Louder Than Hell We Promised That We Would
When Losers Say Its Over With You Know That It’s A Lie
The Gods Made Heavy Metal And It’s Never Gonna Die"

THE GODS MADE HEAVY METAL/by
ManOwaR


[edited by - Estor on August 9, 2003 12:57:51 PM]

Share this post


Link to post
Share on other sites
Try adding the .386(or .486) directive just after the .MODEL directive. They both use a 16bit jump for the J(condition) instructions. So the label can be in the range of -32,768 to +32,767 from the jump instruction.


EDIT: Oh... NM, you said the problem was the LOOP instruction.

[edited by - Xanth on August 9, 2003 4:10:29 PM]

Share this post


Link to post
Share on other sites