汇编王爽老师,实验16,改变前景色,背景色

实现在8086汇编中使用直接定址表
这篇博客介绍了如何在8086汇编程序中处理直接定址表的问题,通过将table数据移至内存特定位置,并使用cs:0202[bx]引用,避免了因编译器导致的未知位置问题。文章详细展示了代码实现,包括数据传输、中断向量表修改以及不同功能子程序的实现,如清屏、前景色改变、背景色改变和滚动等操作。

  这个程序的难点时直接定址表的使用。课本上 table数据标号,在代码移入0000:0200位置后,就会由于编译器的原因,把table处理成一个我们不知道的位置,标号的参考基点的位置发生了变化。参考别人的代码,直接用cs:0202[bx]引用定址表,采用绝对地址。这样也很方便,很容易理解,不再使用 table 标号。

assume cs:code
code segment
main:
	mov ax,cs
	mov ds,ax
	mov si,offset screen;传送的数据源
	
	mov ax,0
	mov es,ax
	mov di,200h;传送的目标地址
	
	cld;传送的方向
	mov cx,offset scrend - offset screen
	rep movsb
	
	cli
	mov ax,0;修改中断向量表
	mov es,ax
	mov word ptr es:[7ch * 4],200h
	mov word ptr es:[7ch * 4 + 2],0
	sti
	
	mov ax,4c00h
	int 21h
	
	screen:
		go:	
			jmp short scrcode 
		table 	dw offset clear0 - offset go + 200h
			dw offset fclr1 - offset go + 200h
			dw offset bclr2 - offset go + 200h
			dw offset scrol3 - offset go + 200h
		
		scrcode:
			push bx
			
			cmp ah,3
			ja codend
			
			mov bl,ah
			add bl,bl
			mov bh,0
			call word ptr cs:202h[bx]
			codend:
				pop bx
		iret
			
			
		clear0:
			push ax
			push cx
			push es
			push di
			
			mov ax,0b800h
			mov es,ax
			mov di,0;设置屏幕
		
			mov cx,2000
			clearlp:
				mov byte ptr es:[di],32
				add di,2
			loop clearlp
			
			pop di
			pop es
			pop cx
			pop ax
		ret


		fclr1:
			push bx
			push cx
			push es
			push di
			
			mov bx,0b800h
			mov es,bx
			mov di,1;设置屏幕es:di
			
			mov cx,2000
			fcollp:
				mov bl,es:[di]
				and bl,11111000b
				
				add bl,al;新前景色属性
				mov es:[di],bl
				
				add di,2
			loop fcollp
			
			pop di
			pop es
			pop cx
			pop bx
		ret

		bclr2:
			push bx
			push cx
			push es
			push di
			
			mov cl,4
			shl al,cl
			
			mov bx,0b800h
			mov es,bx
			mov di,1;设置屏幕es:di
			
			mov cx,2000
			bcollp:
				mov bl,es:[di]
				and bl,10001111b
				
				add bl,al;新前景色属性
				mov es:[di],bl
				
				add di,2
			loop bcollp
			
			pop di
			pop es
			pop cx
			pop bx
			
		ret
		
		scrol3:
			push bx
			push cx
			push es
			push di
			
			mov cx,0b800h
			mov es,cx	
			mov di,0;屏幕
			
			mov cx,1920
			scllp:
				mov bl, es:[di + 160]
				mov es:[di],bl
				add di,2
			loop scllp
		
			mov cx,80
			spacelp:
				mov byte ptr es:[di],' '
				add di,2
			loop spacelp
			pop di
			pop es
			pop cx
			pop bx
		ret
	scrend: nop
code ends
end main

下面是一个主程序

assume cs:code

code segment
main:
	mov ah,3
	mov al,5
	int 7ch

	mov ax,4c00h
	int 21h
code ends
end main

效果如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

谢谢阅读

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangzhangkeji

谢谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值