蒙珣的博客

活好当下,做好今天该做的事情。

0%

实验12 编写0号中断的处理程序

编写0号中断处理程序,使得在除法溢出发生时,在屏幕中间显示字符串“divide error”,然后返回dos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
assume cs:code

code segment

start: mov ax,cs
mov ds,ax
mov si,offset do0 ;设置ds:si指向源地址
mov ax,0
mov es,ax
mov di,200h ;设置es:di指向目的地址
;设置cx为传输长度
mov cx,offset do0end-offset do0
cld ;设置传输方向为正
rep movsb

; 设置中断向量

mov ax,0
mov es,ax
mov word ptr es:[0*4],200h
mov word ptr es:[0*4+2],0

do0: jmp short do0start
db "divide error!"

do0start: mov ax,cs
mov ds,ax
mov si,202h ;设置ds:si字符串

mov ax,0b800h
mov es,ax
mov di,12*160 + 36*2

mov cx,13
s: mov al,[si]
mov es:[di],al
inc si
add di,2
loop s

mov ax,4c00h
int 21h

do0end: nop

code ends
end start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

assume cs:code,ds:data,ss:stack

data segment
db 'divide error',0 ;会被覆盖掉 CPU需要立刻处理的程序
;0:200 0:3FF
data ends

stack segment stack
db 128 dup (0)
stack ends

code segment

start: mov ax,stack
mov ss,ax
mov sp,128

call cpy_new_int0
call set_new_int0

mov ax,0
mov dx,1
mov bx,1
div bx

mov ax,4c00h
int 21h


;===================================
set_new_int0: mov bx,0
mov es,bx

mov word ptr es:[0*4],7e00h
mov word ptr es:[0*4+2],0

ret

;===================================
new_int0: jmp newint0

string: db 'divide error',0

newint0: mov bx,0800h
mov es,bx

mov bx,0
mov ds,bx

mov di,160*10 + 30*2
mov si,7e03h

mov dl,ds:[si]
cmp dl,0
je showStringRet
mov es:[di],dl
add di,2
inc si
jmp showString

mov ax,4c00h
int 21h

new_int0_end: nop

;===================================
cpy_new_int0: mov bx,cs
mov ds,bx
mov si,offset new_int0

mov bx,0
mov es,bx
mov di,7e00h

mov cx,offset new_int0_end - new_int0
cld
rep movsb

ret

code ends

end start