8086汇编学习小记王爽汇编语言实验13

(1)编写并安装int 7ch中断例程,在dh行,dl列用cl颜色属性从ds:si处输出以0结尾的字符串。

编写中断程序时要注意保护现场。安装程序如下:

 1 assume cs : codesg, ss : stacksg
 2 
 3 stacksg SEGMENT
 4     dw 16 dup (0)
 5 stacksg ENDS
 6 
 7 
 8 
 9 codesg SEGMENT
10 
11 start:    mov ax, 0
12     mov es, ax
13     mov di, 0200h
14     mov ax, codesg
15     mov ds, ax
16     mov si, offset do0
17     
18     cld
19     mov cx, offset do0end - offset do0
20     rep movsb
21     
22     mov word ptr es : [07ch * 4], 0200h
23     mov word ptr es : [07ch * 4 + 2], 0
24 
25     mov ax, 4c00h
26     int 21h
27 
28 do0:    push ax
29     push es
30     push di
31     push si
32     mov ax, 0b800h
33     mov es, ax
34     mov al, dh
35     mov ah, 0
36     mov di, 160
37     mul di
38     mov di, ax
39     mov si, 2
40     mov al, dl
41     mov ah, 0
42     mul si
43     add di, ax
44     pop si
45 s:    mov al, [si]
46     mov es : [di], al
47     mov es : [di + 1], cl
48     add si, 1
49     add di, 2
50     cmp al, 0
51     jne s
52 
53     pop di
54     pop es
55     pop ax
56     iret
57 do0end: nop
58 
59 codesg ENDS
60 END start

使用int 7ch中断例程:

View Code
 1 datasg segment
 2     db 'welcome to masm!', 0
 3 datasg ends
 4 
 5 codesg SEGMENT:
 6 
 7 start:    mov ax, datasg
 8             mov ds, ax
 9             mov si, 0
10             mov cl, 02h
11             mov dh, 12
12             mov dl, 36    
13             int 7ch       
14                 mov ax, 4c00h
15                 int 21h
16 codesg ENDS
17 END start

(2)编写安装int 7ch中断,完成loop指令功能,cx为循环次数,bx为偏移位移。

 1 ;中断时的入栈顺序是pushf,push cs, push ip
 2 assume cs : codesg, ss : stacksg
 3 
 4 stacksg SEGMENT
 5     dw 16 dup (0)
 6 stacksg ENDS
 7 
 8 
 9 
10 codesg SEGMENT
11 
12 start:    mov ax, 0
13         mov es, ax
14         mov di, 0200h
15         mov ax, codesg ;需要安装的程序所在的段
16         mov ds, ax
17         mov si, offset int7c ;需要安装的程序的偏移
18 
19         mov cx,  offset int7cend - offset int7c
20         cld
21         rep movsb
22 
23         mov word ptr es : [7ch * 4], 0200h
24         mov word ptr es : [7ch * 4 + 2], 0
25 
26         mov ax, 4c00h
27         int 21h
28 
29 int7c:     push si
30         push bp
31         mov bp, sp
32         add bp, 4   ;find the pre-ip
33         mov si, ss : [bp] ;赋值ip->si
34         dec cx
35         jcxz s
36         add si, bx    ;cx不为0则改变栈中的ip值
37         mov ss : [bp], si
38     s:    pop bp
39         pop si
40         iret
41 int7cend:    nop
42 codesg ENDS
43 END start
44             

之后测试int 7ch时在第一行循环打印‘a’,结果没有出现,原因是命令行换行把显存里的东西刷新了。

测试结果:

原文地址:https://www.cnblogs.com/ACystalMoon/p/2762180.html