实验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 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指令,能否替换成如下代码?你的结论的依据/理由是什么?

1 add si, 2
2 add di, 2

不可以,替换代码后,重新编译运行,结果出错,结果如下

 

理由:add指令对进位标志位CF(Carry Flag)有影响,inc指令对进位标志位CF(Carry Flag)没有影响。

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

做128位加之前:

做128位加之后:

  • 试验任务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
运行测试截图
① 汇编指令代码line11-18,实现的功能是?  
答:输入一个以#为末尾的字符串。
② 汇编指令代码line20-22,实现的功能是?  
答:输出一个换行符。
③ 汇编指令代码line24-30,实现的功能是?  
答:输入与输入相同的字符串。
  • 试验任务3

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 stack segment
 7     db 64 dup(0)
 8     top equ $+1
 9 stack ends
10 code segment
11 start:
12     mov ax,data
13     mov ds,ax
14     mov ax,stack
15     mov ss,ax
16     mov sp,top
17 
18     mov cx,len/2
19     mov bx,0
20 s1:
21     mov ax,ds:[bx]
22     push bx
23     push cx
24     call printNumber
25     call printSpace
26     pop cx
27     pop bx
28     add bx,2
29     loop s1
30 
31     mov ah,4ch
32     int 21h
33 
34 printNumber:
35     mov bx,10
36     mov cx,0
37 s2:
38     mov dx,0
39     div bx
40     push dx
41     inc cx
42     cmp ax,0
43     jne s2
44 
45 s3:
46     mov ah,2
47     pop dx
48     or dl,30h
49     int 21h
50     loop s3
51     ret
52 
53 printSpace:
54     mov ah,2
55     mov dl,' '
56     int 21h
57     ret
58 
59 code ends
60 end start

运行测试截图

  • 试验任务4

task4.asm源码

 1 assume cs:code,ds:data
 2 
 3 data segment
 4     str db "assembly language, it's not difficult but tedious"
 5     len equ $ - str
 6 data ends
 7 
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12     mov si, offset str
13     mov cx, len
14     call strupr;
15     mov ax, 4c00h
16     int 21h
17 
18 strupr:
19     mov al, [si]
20     cmp al, 97
21     jb s
22     cmp al, 122
23     ja s
24     and al, 0dfh
25     mov [si], al
26   s:inc si
27     loop strupr
28     ret
29 code ends
30 end start

在debug中调试截图

 

 

 

  • 试验任务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 star
程序运行测试截图:
程序功能:判断输入的字符是否是‘7’,是输出yes,不是输出no。
  • 试验任务6

 

软中断即是程序中通过 int 指令引起的,当设置一种中断程序时需要将其加入中断向量表,即该程序的入口地址,当程序执行时遇到int指令引发中断,cpu会获得中断号,再根据中断号×4即可得到中断程序段入口的段地址和偏移地址,进而执行中断程序。

posted @ 2021-12-10 15:56  华非桦  阅读(71)  评论(4)    收藏  举报