实验4 8086标志寄存器及中断
1. 实验任务1
- 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, 3912h data ends code 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, 8 s: 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 ret code ends end start
回答问题
- line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?

答:并不能,因为inc和loop指令不影响CF位,而add,si,2可能会改变CF位,add si,2可能会影响之前产生的进位CF,但在本题貌似不会出现对数据的影响。

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

调试后:

2. 实验任务2
- 程序task2.asm源码
assume cs:code, ds:data data segment str db 80 dup(?) data ends code segment start: mov ax, data mov ds, ax mov si, 0 s1: mov ah, 1 int 21h mov [si], al cmp al, '#' je next inc si jmp s1 next: mov ah, 2 mov dl, 0ah int 21h mov cx, si mov si, 0 s2: mov ah, 2 mov dl, [si] int 21h inc si loop s2 mov ah, 4ch int 21h code ends end start
- 运行测试截图

- 回答问题
运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。结合运行结果,理解代码并回答问题:
① 汇编指令代码line11-18,实现的功能是?
② 汇编指令代码line20-22,实现的功能是?
③ 汇编指令代码line24-30,实现的功能是?
答:①实现功能为:从键盘中输入数据然后将其传入数据段中,当遇到#号时跳转到next程序段,否则进行循环输入
② 实现功能:将#变成换行符;
③实现功能在:将#号前的数据显示在屏幕上
3. 实验任务3
- task3.asm源码
assume cs:code, ds:data data segment x dw 91, 792, 8536, 65521, 2021 len equ $- x data ends stack segment dw 8 dup(?) stack ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, len/2 mov bx,10 mov ax ,stack mov ss,ax mov sp,16 s1: mov ax,word ptr ds:[si] push cx call printNumber call printSpace inc si inc si pop cx loop s1 mov ah, 4ch int 21h printSpace proc mov ah, 2 mov dl, ' ' int 21h ret printSpace endp printNumber proc mov di,0;计数 s2:mov dx,0 div bx;除数16位 push dx;余数入栈 inc di cmp ax,0 jne s2 mov cx,di; s3: mov ah,2 pop dx or dl,30h;只考虑dl就可以了,每次/10的余数肯定存在低位 int 21h loop s3 ret printNumber endp code ends end start
- 运行测试截图

4. 实验任务4
- task4.asm源码
assume cs:code, ds:data data segment str db "assembly language, it's not difficult but tedious" len equ $ - str data ends code segment start: mov ax,data mov ds,ax mov si,offset str mov cx,len; s1: call strupr inc si loop s1 mov ah,4ch int 21h strupr proc mov al,byte ptr ds:[si] cmp al,96 ja s2 s2: cmp al,123 jb s3 s3: mov bx,20h sub ds:[si],bx ret strupr endp code ends end start
- 在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)
调用前

调用后

5. 实验任务5
- task5.asm源码
assume cs:code, ds:data data segment str1 db "yes", '$' str2 db "no", '$' data ends code segment start: mov ax, data mov ds, ax mov ah, 1 int 21h ; 从键盘输入字符 mov ah, 2 mov bh, 0 mov dh, 24 ; 设置光标位置在第24行 mov dl, 70 ; 设置光标位置在第70列 int 10h ; 设置光标位置 cmp al, '7' je s1 mov ah, 9 mov dx, offset str2 int 21h ; 显示标号str2处的字符串 jmp over s1: mov ah, 9 mov dx, offset str1 int 21h ; 显示标号str2处的字符串 over: mov ah, 4ch int 21h code ends end start
- 程序运行测试截图(输入7,以及输入其他字符,运行结果截图)


- 程序的功能是?
遇到‘7‘在行末显示yes,遇到其他在行末显示no
6. 实验任务6
通过此项实现任务,你对中断、软中断实现机制的理解
调用结果:
理解:
1.对于int指令来说,其中断过程为:取中断类型码n,标志寄存器入栈:IF=0,TF=0;CS,IP入栈;(IP)=(n*4),(CS)=(n*4+2);
2.编程处理中断程序时,分为两步,(1)安装,设置中断向量的程序,(2)编写中断处理程序
3.中断向量表必须存储在内存固定的单元中,在8086中,中断向量表就需要放在0000:0000~0000:03FF的内存单元中,在上面程序中中断向量表就是存放在0000:0200内存单元中
4.iret出栈顺序为IP,CS,标志寄存器,刚好和寄存器入栈的顺序相对应。

浙公网安备 33010602011771号