王爽《汇编语言》实验13:编写、应用中断例程

1.编写并安装int 7ch中断程序,功能为显示一个以0结束的字符串,中断安装在0:200处

参数:
(dh)=行号,(dl)列号,(cl)=颜色,ds:si->字符串
测试程序:

assume cs:codesg
datasg segment
    db 'welcome to masm!',0
datasg ends

codesg segment
start:
    mov dh,10       ;(dh)=行号
    mov dl,10       ;(dl)=列号
    mov cl,2        ;(cl)=颜色
    mov ax,datasg
    mov ds,ax
    xor si,si       ;ds:si->字符串
    int 7ch

    mov ax,4c00h
    int 21h
codesg ends
end start

int 7ch中断例程:

assume cs:codesg
codesg segment
start:      ;中断do0安装程序
    mov ax,cs
    mov ds,ax
    mov si,offset do0
    mov ax,0
    mov es,ax
    mov di,200h
    cld
    mov cx,(offset d_e - offset do0)
    rep movsb

    mov di,(7ch*4)
    mov word ptr es:[di],200h
    mov word ptr es:[di+2],0

    mov ax,4c00h
    int 21h

do0:
    push ax
    push bx
    push cx
    push dx     
    push si     ;保存用到的寄存器

    mov bh,0    ;第0页,固定值
    mov bl,cl   ;字体颜色,固定值
    mov cx,1    ;字符重复个数,固定值

s:  cmp byte ptr ds:[si],0
    je ok
    mov ah,2
    int 10h     ;设置光标位置
    mov ah,9
    mov al,ds:[si]
    int 10h     ;向光标位置打印字符
    inc si      ;ds:si->字符串下一字符
    inc dl      ;使光标指向下一列
    jmp s
    
ok: pop si      ;恢复用到的寄存器
    pop dx      
    pop cx
    pop bx
    pop ax
    iret
d_e:nop
codesg ends
end start

运行截图:
王爽《汇编语言》实验13:编写、应用中断例程

2.编写安装int 7ch,功能为完成loop指令功能

测试程序:

assume cs:codesg
codesg segment
start:
    mov ax,0b800h
    mov es,ax
    mov di,160*12
    mov bx,offset s-offset se
    mov cx,80
s:  mov byte ptr es:[di],'!'
    add di,2
    int 7ch

se: nop
    mov ax,4c00h
    int 21h
codesg ends
end start

int 7ch中断例程:

assume cs:codesg
codesg segment
start:      ;中断do0安装程序
    mov ax,cs
    mov ds,ax
    mov si,offset do0
    mov ax,0
    mov es,ax
    mov di,200h
    cld
    mov cx,(offset d_e - offset do0)
    rep movsb

    mov di,(7ch*4)
    mov word ptr es:[di],200h
    mov word ptr es:[di+2],0

    mov ax,4c00h
    int 21h

do0:
    push bp

    mov bp,sp
    dec cx
    jcxz d_r
    add ss:[bp+2],bx

d_r:pop bp
    iret
d_e:nop
codesg ends
end start

...这个忘截图额,就是中间打印了一排'!'

3.补全程序,分别在屏幕第2、4、6、8行打印诗句

答案:

	mov,ds:[si]
	mov dx,ds:[bx]
	inc si
	add bx,2

程序代码:

assume cs:codesg
codesg segment
s1: db 'Good,better,best,$'
s2: db 'Never let it rest,$'
s3: db 'Till goog is better,$'
s4: db 'And better,best.$'
s:  dw offset s1,offset s2,offset s3,offset s4
row:db 2,4,6,8

start:
    mov ax,cs
    mov ds,ax
    mov bx,offset s
    mov si,offset row
    mov cx,4
ok: mov bh,0
    mov dh,ds:[si]
    mov dl,0
    mov ah,2
    int 10h

    mov dx,ds:[bx]
    mov ah,9
    int 21h
    inc si
    add bx,2
    loop ok
    
    mov ax,4c00h
    int 21h
codesg ends
end start

运行截图:
王爽《汇编语言》实验13:编写、应用中断例程

上一篇:AcWing 1230 K倍区间


下一篇:C++ 容器及选用总结