实验4 8086标志寄存器及中断
四、实验结论
1. 实验任务1
此部分书写内容:
- task1.asm源码
1 assume cs:code, ds:data 2 3 data segment 4 x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h 5 y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h 6 data ends 7 code segment 8 start: 9 mov ax, data 10 mov ds, ax 11 mov si, offset x 12 mov di, offset y 13 call add128 14 15 mov ah, 4ch 16 int 21h 17 18 add128: 19 push ax 20 push cx 21 push si 22 push di 23 24 sub ax, ax 25 26 mov cx, 8 27 s: mov ax, [si] 28 adc ax, [di] 29 mov [si], ax 30 31 inc si 32 inc si 33 inc di 34 inc di 35 loop s 36 37 pop di 38 pop si 39 pop cx 40 pop ax 41 ret 42 code ends 43 end start
- 回答问题
line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?
不能替换,因为add 影响进位标志而inc 不影响进位标志。
- 在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截图。
2. 实验任务2
此部分书写内容:
- 程序task2.asm源码
1 assume cs:code, ds:data 2 data segment 3 str db 80 dup(?) 4 data ends 5 6 code segment 7 start: 8 mov ax, data 9 mov ds, ax 10 mov si, 0 11 s1: 12 mov ah, 1 13 int 21h 14 mov [si], al 15 cmp al, '#' 16 je next 17 inc si 18 jmp s1 19 next: 20 mov ah, 2 21 mov dl, 0ah 22 int 21h 23 24 mov cx, si 25 mov si, 0 26 s2: mov ah, 2 27 mov dl, [si] 28 int 21h 29 inc si 30 loop s2 31 32 mov ah, 4ch 33 int 21h 34 code ends 35 end start
- 运行测试截图
- 回答问题
运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。结合运行结果,理解代码并回答问题:
① 汇编指令代码line11-18,实现的功能是?
从键盘上输入一串以#结尾的字符,将字符的Ascii码值存储到数据段ds中。
② 汇编指令代码line20-22,实现的功能是?
0ah是换行符的ASCII码,这里是在屏幕上输出换行的功能。
③ 汇编指令代码line24-30,实现的功能是?
在屏幕上打印输入的除‘#’以外的字符串。
3. 实验任务3
此部分书写内容:
- task3.asm源码
1 assume cs:code, ds:data, ss:stack 2 data segment 3 x dw 91, 792, 8536, 65521, 2021 4 len equ $ - x 5 data ends 6 7 stack segment 8 db 16 dup(?) 9 stack ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 mov ax, stack 16 mov ss, ax 17 mov sp, 16 18 mov si, offset x 19 mov cx, len/2 20 mov bx,10 21 call print 22 23 mov ah,4ch 24 int 21h 25 26 print: 27 mov ax, [si] 28 s1:mov dx,0 29 div bx 30 push dx;存余数dx 31 cmp ax,0ah;判断商大于等于10 32 jnb s1 33 34 printNumber: 35 ;打印数字 36 push ax 37 s2:pop dx 38 or dx,30h 39 mov ah,2 40 int 21h 41 cmp sp,0eh 42 jne s2 43 44 printSpace: 45 ;打印空格 46 mov dl, ' ' 47 int 21h 48 49 inc si 50 inc si 51 loop print 52 ret 53 54 code ends 55 end start
- 运行测试截图
4. 实验任务4
此部分书写内容:
- task4.asm源码
1 assume cs:code, ds:data 2 data segment 3 str db "assembly language,it's not difficult but tedious" 4 len equ $ - str 5 data ends 6 7 code segment 8 start: 9 mov ax, data 10 mov ds, ax 11 mov si, offset str 12 mov cx, len 13 call strup 14 15 mov ah,4ch 16 int 21h 17 18 strup: 19 mov al,[si] 20 cmp al,61h 21 jb s 22 cmp al,7ah 23 ja s 24 sub al,20h 25 mov [si],al 26 s: inc si 27 loop strup 28 ret 29 30 code ends 31 end start
- 在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)
5. 实验任务5
此部分书写内容:
- task5.asm源码
1 assume cs:code, ds:data 2 3 data segment 4 str1 db "yes", '$' 5 str2 db "no", '$' 6 data ends 7 8 code segment 9 start: 10 mov ax, data 11 mov ds, ax 12 13 mov ah, 1 14 int 21h 15 16 mov ah, 2 17 mov bh, 0 18 mov dh, 24 19 mov dl, 70 20 int 10h 21 22 cmp al, '7' 23 je s1 24 mov ah, 9 25 mov dx, offset str2 26 int 21h 27 28 jmp over 29 30 s1: mov ah, 9 31 mov dx, offset str1 32 int 21h 33 over: 34 mov ah, 4ch 35 int 21h 36 code ends 37 end start
- 程序运行测试截图(输入7,以及输入其他字符,运行结果截图)
- 程序的功能是?
判断从键盘上输入的字符是否为‘7’,如果是在当前页面第24行第70列打印yes,如果不是则打印no。
6. 实验任务6
此部分书写内容:
- 通过此项实现任务,你对中断、软中断实现机制的理解
当CPU中以下四种情况发生时,会产生相应的中断信息。
(1)除法错误,比如,执行div指令产生的除法溢出;
(2)单步执行;
(3)执行into指令;
(4)执行int指令。
8086CPU收到中断信息后,会引发中断过程。
(1)从中断信息中取得中断类型码;
(2)标志寄存器的值入栈;
(3)设置标志寄存器的第8位TF和第9位IF的值为0;
(4)CS的内容入栈;
(5)IP的内容入栈;
(6)从内存地址为中断类型码*4和中断类型码*4+2的两个字单元中读取中断处理程序的入口地址设置IP和CS。
处理完中断过程,CPU开始执行由程序员编写的中断处理程序。iret通常和硬件自动完成的中断过程配合使用,iret指令执行后,CPU回到执行中断处理程序前的执行点继续执行程序。
五、实验总结(选)
cld相对应的指令是std,二者均是用来操作方向标志位DF(Direction Flag)。cld使DF 复位,即是让DF=0,std使DF置位,即DF=1.这两个指令用于串操作指令中。通过执行cld或std指令可以控制方向标志DF,决定内存地址是增大(DF=0,向高地址增加)还是减小(DF=1,向地地址减小)。









浙公网安备 33010602011771号