汇编语言直接定指标的应用实验16代码

代码解释如下:

;汇编语言王爽  直接定址表  实验16 
assume cs:code,ds:data,ss:stack

data segment
	db 128 dup(0)
data  ends
stack segment
	db 128 dup(0)
stack ends

code segment
start:				mov ax,stack
					mov ss,ax
					mov sp,128
					call cpy_newInt7ch			;复制定义的新的int7ch中断处理程序
					call set_newInt7ch			;设置中断向量表
					mov ah,2					;初始化参数,执行哪个子程序
					mov al,10111010B			;al存颜色参数
					int 7ch						;执行7ch中断程序
					mov ax,4c00h
					int 21h
;=========================================================	设置新的中断程序
new_int7ch:			jmp newInt7chStart
TABLE				dw offset clear_screen 	- 	offset new_int7ch +7e00h	;记录每个子程序的入口地址,参数0
					dw offset set_pre_screen - 	offset new_int7ch +7e00h	;参数1
					dw offset set_back_screen - offset new_int7ch +7e00h	;参数2					
					dw offset set_up_scroll - 	offset new_int7ch +7e00h	;参数3
newInt7chStart:		push bx
					push es
					push ax
					
					mov bx,0
					mov es,bx
					mov bl,ah
					add bx,bx					;存储程序地址的是双字,所以bx加倍
					add bx,offset TABLE - offset new_int7ch + 7e00h
					call word ptr es:[bx]
					
					pop ax
					pop es
					pop bx
					iret										;中断程序用iret返回
					
;=========================================================		清屏					
clear_screen:		push cx
					push bx
					push es
					push di
					mov cx,2000
					mov bx,0b800h
					mov es,bx
					mov di,0
clearScreen:		mov es:[di],0700h
					add di,2
					loop clearScreen
					
					pop di
					pop es
					pop bx
					pop cx
					ret
;=========================================================		设置前景色
set_pre_screen:		push cx
					push bx
					push es
					push ax
					mov cx,2000
					mov bx,0b800h
					mov es,bx
					mov bx,1
changePreColor:		and byte ptr es:[bx],11111000B
					or byte ptr es:[bx],al
					add bx,2
					loop changePreColor
					
					pop ax
					pop es
					pop bx
					pop cx
					ret
;=========================================================		设置背景色
set_back_screen:	push cx
					push bx
					push es
					push ax
					
					mov cx,2000
					mov bx,0b800h
					mov es,bx
					mov bx,1
changeBackColor:	and byte ptr es:[bx],10001111B
					or byte ptr es:[bx],al
					add bx,2
					loop changeBackColor
					
					pop ax
					pop es
					pop bx
					pop cx
					ret
;=========================================================		向上滚动一行
set_up_scroll:		push bx
					push es
					push ds
					push di
					push si
					push cx
					
					mov bx,0b800h
					mov es,bx
					mov ds,bx
					mov di,0
					mov si,160
					mov cx,24*160
					rep movsb
					mov cx,80
setNull:			mov di,160*24								;设置最后一行为空
					mov es:[di],0700h
					add di,2
					loop setNull
					
					pop cx
					pop si
					pop di
					pop ds
					pop es
					pop bx
					ret
;=========================================================					
new_int7chEnd:		nop					
;========================================================== 	复制中断程序
cpy_newInt7ch:		push ax
					push ds
					push si
					push es
					push di
					push cx
					
					mov ax,cs
					mov ds,ax
					mov si,offset new_int7ch
					mov ax,0
					mov es,ax
					mov di,7e00h
					mov cx,offset new_int7chEnd - offset new_int7ch
					cld											;每次执行后si,di加 1,
					rep movsb
					
					pop cx
					pop di
					pop es
					pop si
					pop ds
					pop ax
					ret
;==========================================================	设置中断向量表
set_newInt7ch:		mov ax,0
					mov es,ax
					cli
					mov word ptr es:[7ch*4],7e00h			;设置IP = 7e00
					mov word ptr es:[7ch*4+2],0				;设置cs = 0000
					sti
					ret
;==========================================================			
code ends
end start


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值