王爽《匯編語言》實驗16:包含多個功能子程序的中斷例程 解答


中斷例程:
assume cs:code

code segment
start:
	mov ax,cs
	mov ds,ax
	mov si,offset setscreen
	mov ax,0
	mov es,ax
	mov di,200h
	mov cx,offset setscreenend-offset setscreen
	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 ax,4c00h
	int 21h
	
	;偽指令,表示下一條指令從偏移地址200H開始,正好和安裝后的偏移地址相同  
	;因為如果沒有ORG 200H,此中斷例程被安裝以后,標號所代表的地址變了,和之前編譯器編譯有別
	org 200h  

;ah中保存了功能號,0清屏,1改前景,2改背景,3上滾動一行
setscreen:
	jmp short set

	table dw sub1,sub2,sub3,sub4

	set:
	push bx
	cmp ah,3
	ja sret
	mov bl,ah
	mov bh,0
	add bx,bx ;dw占2個字節,乘2來取得對應位置

	
	call word ptr table[bx]

	sret:
	pop bx
	iret

	sub1:
	push bx
	push cx
	push es
	mov bx,0b800h
	mov es,bx
	mov bx,0
	mov cx,2000
	sub1s:
	mov byte ptr es:[bx],' '
	add bx,2
	loop sub1s
	pop es
	pop cx
	pop bx
	ret
	
	;改變前景色,al中保存了顏色值
	sub2:
	push bx
	push cx
	push es
	mov bx,0b800h
	mov es,bx
	mov bx,1
	mov cx,2000
	sub2s:
	add byte ptr es:[bx],11111000b
	or es:[bx],al
	add bx,2
	loop sub2s
	pop es
	pop cx
	pop bx
	ret

	;改變背景色,al中保存了顏色值
	sub3:
	push bx
	push cx
	push es
	mov cl,4
	shl al,cl
	mov bx,0b800h
	mov es,bx
	mov bx,1
	mov cx,2000
	sub3s:
	add byte ptr es:[bx],10001111b
	or es:[bx],al
	add bx,2
	loop sub3s
	pop es
	pop cx
	pop bx
	ret

	sub4:
	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
	sub4s:
	push cx
	mov cx,160
	rep movsb
	pop cx
	loop sub4s
	mov cx,80
	mov si,0
	sub4s1:
	mov byte ptr [160*24+si],' '
	add si,2
	loop sub4s1
	pop ds
	pop es
	pop di
	pop si
	pop cx
	ret

setscreenend:
	nop
code ends
end start


測試程序:
assume cs:code
code segment
;為了看到效果,我們最后做清屏
start:
	mov ah,1
	mov al,1
	int 7ch
	call delay
	mov ah,2
	mov al,2
	int 7ch
	call delay
	mov ah,3
	int 7ch
	call delay
	mov ah,0
	int 7ch
	
	mov ax,4c00h
	int 21h

delay:
	push ax
	push dx
	mov dx,1000h
	mov ax,0
	s1:
	sub ax,1
	sbb dx,0
	cmp ax,0
	jne s1
	cmp dx,0
	jne s1
	pop dx
	pop ax
	ret

code ends
end start



注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: