实验4 8086标志寄存器及中断

发布时间:2022-06-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了实验4 8086标志寄存器及中断脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

三、实验内容1. 实验任务1验证性实验:有些汇编指令会影响到标志寄存器中的一个或多个状态标志位。在debug环境中,分别实践、观察:① add指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?② inc指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?

实验4 8086标志寄存器及中断

 

 

实验4 8086标志寄存器及中断

 

 add对零标志位有影响,对进位标志位有影响,inc对零标志位有影响,对进位标志位无影响。

task1.asm源码

assume cs:code, ds:data

data segment x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912hdata endscode segment start: mov ax, data mov ds, ax mov si, offset x mov di, offset y call add128

mov ah, 4ch int 21h

add128: push ax push cx push si push di

sub ax, ax

mov cx, 8s: mov ax, [si] adc ax, [di] mov [si], ax

inc si inc si inc di inc di loop s

pop di pop si pop cx pop ax retcode endsend start

回答问题line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?

实验4 8086标志寄存器及中断

不能,因为下面loop s执行跳转(cx不为0的情况下)后即将要执行的指令有adc ax, [di], ax=ax+[di]+CF , add 对 CF 有影响,而inc 对CF无影响。

在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截图。

实验4 8086标志寄存器及中断

 

128位加之前

 

实验4 8086标志寄存器及中断

 

 

实验4 8086标志寄存器及中断

 

128位加之后

 

实验4 8086标志寄存器及中断

 

 

 

2. 实验任务2此部分书写内容:程序task2.asm源码

assume cs:code, ds:datadata segment str db 80 dup(?)data ends

code segmentstart: mov ax, data mov ds, ax mov si, 0s1: mov ah, 1 int 21h mov [si], al cmp al, '#' je next inc si jmp s1next: mov ah, 2 mov dl, 0ah int 21h mov cx, si mov si, 0s2: mov ah, 2 mov dl, [si] int 21h inc si loop s2

mov ah, 4ch int 21hcode endsend start

运行测试截图

实验4 8086标志寄存器及中断

 

 

实验4 8086标志寄存器及中断

 

 

回答问题运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。结合运行结果,理解代码并回答问题:

实验4 8086标志寄存器及中断

① 汇编指令代码line11-18,实现的功能是?

读一个字符,并将这个字符放入si指向的位置,若该字符等于#,则跳转到next,否则继续读入下一个字符② 汇编指令代码line20-22,实现的功能是?

换行③ 汇编指令代码line24-30,实现的功能是?

 输出除了#以外的,上面读入的字符。

 

3. 实验任务3

针对8086CPU,已知逻辑段定义如下:编写8086汇编源程序task3.asm,在屏幕上以十进制形式输出data段中这一组连续的数据,数据和数据之间以空格间隔。要求:编写子程序printNumber功能:以十进制形式输出一个任意位数的整数(整数范围0 ~ 65535)入口参数:寄存器ax(待输出的数据 --> ax)出口参数:无编写子程序printSpace功能:打印一个空格入口参数:无出口参数:无在主体代码中,综合应用寻址方式和循环,调用printNumber和printSpace, 实现题目要求。

此部分书写内容:task3.asm源码

assume ds:data, cs:code data segment x dw 91, 792, 8536, 65521, 2021 len equ $ - x y db 200 dup(?)  leny equ $ - y data ends code segment start: mov ax, offset y mov ss, ax mov sp, leny  mov ax, data  mov ds, ax mov si, 0 mov cx, 5 s2: call printNumber call printSpace add si, 2 loop s2 mov ah, 4ch int 21h

printNumber: push cx  mov ax, ds:[si]  mov dx, 0  mov bx, 10 mov cx, 0h s1: inc cx  div bx or dx, 30h  push dx  mov dx, 0  cmp ax, 0 jne s1 s3: pop dx  mov ah, 02h int 21h loop s3  pop cx  ret printSpace: mov dl, ' ' mov ah, 02h int 21h ret code ends end start

运行测试截图

实验4 8086标志寄存器及中断

 

 

4. 实验任务4此部分书写内容:task4.asm源码

assume ds:data, cs:codedata segmentstr db "assembly language, it's not difficult but tedious"len equ $ - strdata ends

code segmentstart:mov ax, datamov ds, axmov si, offset strmov cx, lens1:call struprinc siloop s1mov ah, 4chint 21hstrupr:cmp byte ptr ds:[si], 96jna s2 sub byte ptr ds:[si], 32 s2:mov dx, ds:[si]mov ah, 2int 21hretcode endsend start

 

assume ds:data, cs:codedata segmentstr db "assembly language, it's not difficult but tedious"len equ $ - strdata ends

code segmentstart:mov ax, datamov ds, axmov si, offset strmov cx, lens1:call struprinc siloop s1mov ah, 4chint 21hstrupr:cmp byte ptr ds:[si], 96jna s2 sub byte ptr ds:[si], 32 s2:mov dx, ds:[si]mov ah, 2int 21hretcode endsend start

实验4 8086标志寄存器及中断

在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)

实验4 8086标志寄存器及中断

 

 

实验4 8086标志寄存器及中断

 

第一次调用结束

 

实验4 8086标志寄存器及中断

 

 

实验4 8086标志寄存器及中断

 

 

5. 实验任务5此部分书写内容:task5.asm源码

 

assume cs:code, ds:data

data segment str1 db "yes", '$' str2 db "no", '$'data ends

code segmentstart: mov ax, data mov ds, ax

mov ah, 1 int 21h

mov ah, 2 mov bh, 0 mov dh, 24 mov dl, 70 int 10h

cmp al, '7' je s1 mov ah, 9 mov dx, offset str2 int 21h

jmp over

s1: mov ah, 9 mov dx, offset str1 int 21hover: mov ah, 4ch int 21hcode endsend start

程序运行测试截图(输入7,以及输入其他字符,运行结果截图)

 

实验4 8086标志寄存器及中断

 

 

 

实验4 8086标志寄存器及中断

 

 

实验4 8086标志寄存器及中断

 

 

 

程序的功能是?

判断输入的字符是否为7,是则输出yes,否则输出no。

6. 实验任务6此部分书写内容:

对汇编源程序task6_1.asm进行汇编、链接,得到可执行程序task6_1.exe。运行task6_1.exe,实现将42号中断处理程序安装到0:200开始的连续内存空间,并设置中断向量表,使得将来通过int 42 ,系统可以跳转到中断处理程序。对汇编源程序task6_2.asm进行汇编、链接,得到可执行程序task6_2.exe。运行task6_2.exe。两个程序正确编写、汇编、链接,运行后,结果如下:

实验4 8086标志寄存器及中断

 

 

通过此项实现任务,你对中断、软中断实现机制的理解

中断是指CPU不再接着向下执行,而是转去处理这个特殊信息。

软中断是内部中断的一种,是由软件引起的非屏蔽型中断。

脚本宝典总结

以上是脚本宝典为你收集整理的实验4 8086标志寄存器及中断全部内容,希望文章能够帮你解决实验4 8086标志寄存器及中断所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: