(汇编语言)实验16 编写包含多个功能子程序的中断例程

版权声明:斌哥版权,如有雷同,纯属虚构 https://blog.csdn.net/iostream992/article/details/84307490

;实验16 编写包含多个功能子程序的中断历程


;安装一个新的int7ch
;1)清屏         clear
;2)设置前景色   setFroeground
;3)设置背景色   setBackground
;4)向上滚动一行 scroll

;入口参数
;用ah寄存器传递功能号:0表示清屏,1表示设置前景色,2表示设置背景色 
;                      3表示向上滚动一行
;对于1、2号功能,用al传递颜色值

assume cs:code
 
 
code segment




;----------------------
setscreen:
	jmp short set
	table dw offset clear + 200h,offset setFroeground + 200h,offset setBackground + 200h,offset scroll+ 200h    

set:	push bx
	push es
	mov bx, 0
	mov es, bx
	cmp ah, 3
	ja sret
	mov bl, ah
	xor bh, bh  ;bh清零
	add bx, bx
	add bx, offset table + 200h
	call word ptr es:[bx]
sret:	pop es
	pop bx
	iret

;--------------------------


start:	
	mov ax, cs    
	mov ds, ax    
	mov si, offset setscreen     ;设置ds:si指向源地址    
	mov ax, 0    
	mov es, ax              
	mov di, 200h            ;设置es:si指目的地址    
 
	mov cx, offset setscreen_end - offset setscreen  ;设置cx传输长度    
	cld    
	rep movsb 
 
 
	mov ax, 0       ;设置中断向量表    
	mov es, ax    
	mov word ptr es:[7ch*4], 200h    
	mov word ptr es:[7ch*4+2], 0 

	mov ah,1; 0清屏 1前景色 2背景色
	mov al,4
	int 7ch
        
 
	mov ax, 4c00h
	int 21h
 
 
;----------------






;1)清屏   clear
;   参数   ah 0
	
clear: 
        push bx 
        push cx 
        push es 
        mov bx,0b800h 
        mov es,bx 
        mov bx,0 
        mov cx,2000 


clear_s:        
	mov byte ptr es:[bx],' ' 
        add bx,2 
        loop clear_s 
        pop es 
        pop cx 
        pop bx 
        ret 


 

;2)设置前景色   setFroeground
;   参数         ah    1
;                al    颜色
setFroeground:   
        push bx 
        push cx 
        push es 
        mov bx,0b800h 
        mov es,bx 
        mov bx,1 
        mov cx,2000 
setFroeground_s:        
	and byte ptr es:[bx],11111000b 
        or es:[bx],al 
        add bx,2 
        loop setFroeground_s 
         
        pop es 
        pop cx 
        pop bx 
        ret 
 
;3)设置背景色   setBackground
;   参数         ah    2
;                al    颜色
setBackground:        
	push bx 
        push cx 
        push es 
        mov cl,4 
        shl al,cl 
        mov bx,0b800h 
        mov es,bx 
        mov bx,1 
        mov cx,2000 
setBackground_s:        
	and byte ptr es:[bx],al 
        or es:[bx],al 
        add bx,2 
        loop setBackground_s 
        pop es 
        pop cx 
        pop bx 
        ret 
 

;4)向上滚动一行 scroll
;   参数   ah    3

scroll:        
	push cx 
        push si 
        push di 
        push es 
        push ds 
         
        mov si,0b800h 
        mov es,si 
        mov ds,si 
        mov si,160 
        mov di,0 
        cld 
        mov cx,24 
         
scroll_s:        
	push cx 
        mov cx,160 
        rep movsb 
        pop cx 
        loop scroll_s 
         
        mov cx,80 
        mov si,0 
scroll_s1:        
	mov byte ptr [160*24+si],' ' 
        add si,2 
        loop scroll_s1 
         
        pop ds 
        pop es 
        pop di 
        pop si 
        pop cx 
        ret 
setscreen_end:
	nop
 
 
code ends
end start

 

猜你喜欢

转载自blog.csdn.net/iostream992/article/details/84307490