Preface: This experiment is experiment 13 in the third edition of "Assembly Language" written by Mr. Wang Shuang (p262)
Experimental environment: DOSBox 0.74-3
Experimental tasks:
(1) Write and install the int 7ch interrupt routine, the function is to display a string ending with 0, and the interrupt routine is installed at 0:200 .
Parameters: (dh)=line number, (dl)=column number, (cl)=color, ds:si points to the first address of the string.
After the above interrupt routines are installed, follow the program below step by step, especially pay attention to observe the status of CS, IP and stack before and after the execution of int and iret instructions.
assume cs:code
data segment
db "welcome to masm!",0
data ends
code segment
start : mov dh,10
mov dl,10
mov cl,2
mov ax,data
mov ds,ax
mov si,0
int 7ch
mov ax,4c00h
int 21h
code ends
end start
Interrupt program installation code:
assume cs:code
code segment
start: ;安装7ch中断例程
mov ax,cs
mov ds,ax
mov si,offset do7ch
mov ax,0
mov es,ax
mov di,200h
mov cx,offset do7chend - offset do7ch
cld
rep movsb
;设置中断向量表
mov ax,0
mov ds,ax
mov word ptr ds:[7ch*4],200h
mov word ptr ds:[7ch*4 + 2],0
mov ax,4c00h
int 21h
do7ch: push ax
push es
push dx
push di
push cx
push si
;将程序使用到的寄存器入栈保存
mov ax,0b800h
mov es,ax
mov al,160
mul dh ;160 x 行号
add al,dl ;160 x 行号 + 列号
adc ah,0
mov di,ax ;di为字符显示位置
;es:di指向字符显示位置
s: mov al,[si]
cmp al,0
je ok ;为0则字符串结束
mov es:[di],al
mov es:[di+1],cl
inc si
add di,2
jmp short s
ok: pop si
pop cx
pop di
pop dx
pop es
pop ax
;恢复寄存器原始值
iret
mov ax,4c00h
int 21h
do7chend: nop
code ends
end start
Test program running results: