COP3402, Example Program

This example is a rewrite of the program on age 142 of the Byte by Byte textbook.

		DOSSEG	
                .MODEL	SMALL 
                .DATA 
 
;Use equates to represent initial values that can be changed
char_count	equ	26	;Number of letters to print                
char_rep	equ	2	;Number of times to print each letter
char_start	equ	'A'	;First letter to print
start_row	equ	00h	;Starting row for cursor 
start_col	equ	00h	;Starting col for cursor 
max_row		equ	25	;Maximum width of print area

crsr_row	db	start_row 
crsr_col	db	start_col
char		db	char_start
                
                .STACK
                .CODE
;The main procedure only initializes DS, calls procedures, and terminates
start:		mov	ax,@DATA
		mov	ds,ax
                
		call	cls
                call	print_data
                
		mov	ax,4C00h
                int 	21h  


;This procedure will clear the screen and position the cursor at 0,0
;The book changes the video mode to clear the scree, I don't like
;that idea.                
cls		proc	near
		mov	ah,06h
                mov	al,00h
                mov	bh,07h 
                mov	cx,0000h
                mov	dh,24
                mov	dl,79
                int	10h  
                
                mov	dh,crsr_row
                mov	dl,crsr_col	
                call	set_cursor	;call procedure to move 
                			;cursor. Pass position in DX                                
                ret
cls		endp


;Procedure to set cursor position. User must load
;DX register before making the call.
set_cursor	proc	near
		mov	ah,02h
                mov	bh,00h
                int	10h
                ret
set_cursor      endp         
                
;Procedure to print a series of characters. 
;	char_count indicates how many characters to print
;	char_rep   indicates howmany times to print each              
print_data	proc	near
                mov	cx,char_count
pr_top:		push	cx		;save loop counter
                			;since cx is used in loop
                mov	dh,crsr_row
                mov	dl,crsr_col	
                call	set_cursor	;call procedure to move 
                			;cursor. Pass position in DX 
                mov	ah,0Ah		;print character at cursor
                mov	al,char
                mov	cx,char_rep	;number of times to repeat character
                int	10h
                
                inc	char
                call	incr_crsr       ;adjust position of cursor
                pop	cx		;restore loop counter
                loop	pr_top		;loop decrements cx
                                               
		ret
print_data	endp   


;This procedure will increment the position of the cursor
;If there isn't enough room on the current row to fit the
;next string of letters, then the row is incremented
;and the column reset to 0                
incr_crsr	proc	near
                add	crsr_col,char_rep
                cmp	crsr_col,max_row - char_rep
                jbe	ic_next
                inc	crsr_row
                mov	crsr_col,0
ic_next:	ret                
incr_crsr	endp                
                end	start