实验4 8086标志寄存器及中断
实验任务一
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 8 code segment 9 start: 10 mov ax,data 11 mov ds,ax 12 13 mov si,offset x 14 mov di,offset y 15 16 call add128 17 18 mov ah,4ch 19 int 21h 20 21 add128: 22 push ax 23 push cx 24 push si 25 push di 26 27 sub ax,ax 28 29 mov cx,8 30 s: 31 mov ax,[si] 32 adc ax,[di] 33 mov [si],ax 34 35 inc si 36 inc si 37 inc di 38 inc di 39 loop s 40 41 pop di 42 pop si 43 pop cx 44 pop ax 45 46 ret 47 code ends 48 end start
2.问题回答:
line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?
add si, 2 add di, 2
答:不能。因为两次inc指令不会改变标识符CF,而add指令可能会改变标识符CF。
验证:
(1)连续两次inc ax
(2)add ax,2

通过对比可以发现,add会对CF产生影响,这有可能在实现多进制加法时多加1。
3.回答问题:
在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截图
(1)做加法前:
![]()
(2)做加法后:

实验任务二
1.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 mov cx, si 24 mov si, 0 25 s2: 26 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
2.运行结果:

3.问题回答;
① 汇编指令代码line11-18,实现的功能是?
答:读入输入的字符。判断如果是"#"则跳转到"next"函数处执行,否则继续读入下一个字符串。
② 汇编指令代码line20-22,实现的功能是?
答:实现换行功能。
③ 汇编指令代码line24-30,实现的功能是?
答:输出除"#"以外先前输入的字符串。
实验任务三
1.task3.asm源码:
1 assume cs:code,ds:data 2 data segment 3 x dw 91, 792, 8536, 65521, 2021 4 len equ $ - x 5 data ends 6 7 stack segment 8 db 64 dup(0) 9 top equ $+1 10 stack ends 11 12 code segment 13 start: 14 mov ax,data 15 mov ds,ax 16 mov ax,stack 17 mov ss,ax 18 mov sp,top 19 20 mov cx,len/2 21 mov bx,0 22 s1: 23 mov ax,ds:[bx] 24 push bx 25 push cx 26 call printNumber 27 call printSpace 28 pop cx 29 pop bx 30 add bx,2 31 loop s1 32 33 mov ah,4ch 34 int 21h 35 36 printNumber: 37 mov bx,10 38 mov cx,0 39 s2: 40 mov dx,0 41 div bx 42 push dx 43 inc cx 44 cmp ax,0 45 jne s2 46 47 s3: 48 mov ah,2 49 pop dx 50 or dl,30h 51 int 21h 52 loop s3 53 ret 54 55 printSpace: 56 mov ah,2 57 mov dl,20h 58 int 21h 59 ret 60 61 code ends 62 end start
2.运行结果:
实验任务四
1.task4.asm源码:
1 assume cs:code,ds:data 2 data segment 3 str db "assembly language, it's not difficult but tedious" 4 len = ($ - str) 5 data ends 6 7 stack segment 8 db 128 dup(0) 9 top equ $ + 1 10 stack ends 11 12 code segment 13 start: 14 mov ax,data 15 mov ds,ax 16 mov ax,stack 17 mov ss,ax 18 mov sp,top 19 20 mov si,0 21 mov cx,len 22 call strupr 23 mov ah,4ch 24 int 21h 25 strupr: 26 s: 27 cmp byte ptr ds:[si],61h 28 jb s1 29 cmp byte ptr ds:[si],7ah 30 ja s1 31 mov dl,ds:[si] 32 and dl,11011111B 33 mov ds:[si],dl 34 s1: 35 inc si 36 loop s 37 ret 38 code ends 39 end start
2.问题回答:
在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)
(1)调用前数据段的值:

(2)调用后数据段的值:

实验任务五
1.task5.asm源码:
1 assume cs:code, ds:data 2 data segment 3 str1 db "yes", '$' 4 str2 db "no", '$' 5 data ends 6 code segment 7 start: 8 mov ax, data 9 mov ds, ax 10 mov ah, 1 11 int 21h ; 从键盘输入字符 12 13 mov ah, 2 14 mov bh, 0 15 mov dh, 24 ; 设置光标位置在第24行 16 mov dl, 70 ; 设置光标位置在第70列 17 18 int 10h ; 设置光标位置 19 cmp al, '7' 20 je s1 21 mov ah, 9 22 mov dx, offset str2 23 int 21h ; 显示标号str2处的字符串 24 25 jmp over 26 s1: mov ah, 9 27 mov dx, offset str1 28 int 21h ; 显示标号str2处的字符串 29 30 over: 31 mov ah, 4ch 32 int 21h 33 code ends 34 end start
2.运行结果:
(1)输入7:

(2)输入其他字符:
![]()
3.程序的功能:
答:判断当前输入的字符是否是7,如果是在光标第70行出输出yes,否则在光标第24行输出no。
实验任务六
1.对中断、软中断实现机制的理解:
(1)中断:当中断源发出中断信号时,CPU暂定当前的程序,转而去执行其他程序,这个流程称为中断。中断可以通过改变CS:IP来实现。
(2)软中断:软中断是CPU内部产生的中断信号,比如除法溢出,或者程序调用中断例程,其实现方式和call类似。
浙公网安备 33010602011771号