汇编语言实验8中断程序设计
- 格式:docx
- 大小:17.93 KB
- 文档页数:6
汇编语言实验报告
Assembly Language Programming Lab
Reports _________________________
班级: __________ 姓名:____________ 学号:____________ 实验H期:_
学院:计算机与通信工程学院—专业:________________ 计算机科学与技术
实验顺序:—实—实验名称:____________________ 中断程序设计_________
实验分数: ______ 考评日期: __________ 指导教师: ---------
一-实验U的
1 •掌握中断的类型,软件中断和硬件中断。
2•掌握中断处埋的过程,埋解中断类型值,中断向量。
3•掌握系统中断以及功能调用。
4 •可以自己设计中断程序
二-实验环境
操作系统:windows xp
编译程序:masm 5. 0
三.实验原理
1.CPU响应中断的条件
(1)当前的指令周期结束
(2)采样到有效的中断请求型号
(3)如果是可屏蔽的中断请求IXTR,检査中断允许标志IF是否为1
(4)C PU正在执行的程序是不是中断服务程序,或者是中断优先级较低的中断服务程序
2.中断响应过程
(1)首先将标志寄存器FLAGS压入堆栈
(2)将TF *J IF清零,IF=O即关中断
(3)将正在运行程序的断点CS和IP压入堆栈
(4)从中断向量表中取出中断向量高两个字节的内容送入CS,取出低两个字节的内容送入IP
(5)转到相应中断源的中断服务程序入口,执行中断处理服务程序
将原有9号中断的程序入口地址放在一个地方保存起来 編写中断处理程序:int9:调用原有的im9中断
将新mt9中断服务程序送入内存0000:0200处; 将im9的入口地址0000:0200存储在中断向量农9号农项中。
源代码: code segment assume csxode start: mov ax.O mov es.ax mov ax,es:[9+4] mov es:[0200h].ax
mov ax,es: [9+4+2]
mov es:[0202h].ax
cli
mov ax,offset int9
mov es:[9+4]•合 X
mov ax,seg int9
sti
mov dx.ofEet int9end-ofiset mt9start
add dx,16
mov ahjlh mov al,0 uit21h
mov aK4ch uit21h
int9 proc near
uit9start:
push ax
push bx push ex push es mov ax.O mov es.ax
m 合l ・60h
pushf
call dword ptr es:[0200h]
四.实验步骤及结果分析 1.修改已有中断处理程序。
修改已有的中断im 911
(1)
(2)
(3)
(4)
emp alJBh jne
uit9iret mov
cx,2000 mov
ax,0b800h
mov es,ax
mov bx、l
s:
inc byte plr
es:[bx] add bx,2
loop s
uit9iret:
pop es
pop ex
popbx
pop ax
iret
int9end:nop int9 endp code ends end start 运行结果:
2 •写自己的中断例程
Int 60h用到了dos中断的int 21h功能
(1)
(2)
(3)
(4) 如果触发该中断,在屏幕上显示•串笑脸;选择60H号中断类型作为笑脸中断类型:编写中断了•程序sinile_face.显示•串笑脸:将该中断了程序的入口地址写入中断向量衣中
设置中断向量
将在DS:DX中的中断向量写入中断向量农中。
格
式:
(5)
(6)
(7)
AH=25H
AL=中断类型号
DS:DX=中断向量ibrr2iH 编写应用程序,触发60H号中断:中断结束后,返回应用程序继续执行; 把中断了程序驻留在内存中。
中断驻留是•种特殊的退出程序功能,它在退出前保留程序占用的内存,使这叮
些内存单元不被其它程序覆盖或占用。
格式:AH=31H
AL=0
0%=驻留程序长度十16
INT21H
AL=0^示返回码。
源代码:
.model sm 合11
■Stack
code
messl db Oah.Odh/enter intem^t!\0ah,0dh?$'
mess2 db 'exit interrupts,
mess3 db Oah.Odh. ^continue or quit
(c/q) ?S' mam proc far
start:
mo\' ax.@code
moY ds4X
mo\' dx.ofiset
smile_face mo\' ax,seg
smile_face mo\' ds.ax
mo\' aL60h
mo\' ah,25h
int21h
conti:
mo\・ dx.ofiset
messl
moA' ah.9
int21h
in( 60h moA' dx.ofiset mess2
mo\' ah.9
int21h
mo\' dx.ofiset mess3
mo\' all. 9 int21h
mo\' ahj int21h
cuq> at'c* je conti mo\・ atO moA' ah31h
moY dx.smiend-smigm-t-16 int21h
main eudp
smile_face proc far
snugm:
sti
mov ex, 10
leng:
mov dLOlh mov ah,2 uit21h
loop leng mov dLOdli uit21h mov dLOah
uit21h cli iret
sniiend:nop sniile_face endp end start 运行结果:
X To adjust the emulated CPU speed, use ctrl-Fll and ctrl-F12- To activ*ate the
keymapper ctrl-Fl.
For more information read the READ惟file in the DOSBox directory.
HAVE FUN?
The DOSBox Team http://wuu•dosbox•com
Z:\>SET BLASTER=ft220 I? DI H5 T6
Z:\>nount c e:/masm Di'ivc C is muuntcd as lucal dircciury e:/masm、
Z:\>c:
C:\> int6Si.exe enter interrupt?
exit interrupt? continue or quit (c/q) ?c <niLer interrupt?
t?xit interruptt continue or quit (c/q) ?q
C:\>
五.实验心得疑问建议
通过本次实验的学习,了解了中断程序设讣的基本思路和方法,明白了中断程序运行的
方式,学会了合理使用保护现场和恢复现场使程序有效运行。