实验4 8086标志寄存器及中断
实验4 8086标志寄存器及中断
实验任务1
-
add指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?
![]()
add指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)均有影响 -
inc指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?
![]()
inc指令对标志寄存器中的零标志位ZF(Zero Flag)有影响、进位标志位CF(Carry Flag)无影响 -
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
- ine31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?
add si, 2
add di, 2
不能,因为在task1.asm代码中使用到adc指令,adc指令需要使用标志寄存器中CF标志位的值;inc指令不影响CF标志位的值,而add指令影响CF标志位的值。

实验任务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
-
结果
![]()
-
汇编指令代码line11-18,实现的功能是?
从键盘输入字符,存放到al中,然后在赋值给ds:si的内存单元。将al中的值和‘#’进行比较,如果不相等,则si增加1,继续进行输入。如果相等,则结束输入,跳转到next指定位置执行。 -
汇编指令代码line20-22,实现的功能是?
输出dl中的字符,0ah对应的字符是换行符。 -
汇编指令代码line24-30,实现的功能是?
将长度为si的字符串赋给cx,然后利用loop循环将从键盘输入的字符输出。
实验任务3
- task3.asm源代码:
assume cs:code,ds:data
data segment
x dw 91, 792, 8536, 65521, 2021
len equ $ - x
data ends
code segment
start:
mov ax,data
mov ds,ax
mov si,0
mov cx,5
s: call printNumber;
call printSpace;
inc si
inc si
loop s
mov ah,4ch
int 21h
printNumber:
push cx;保存cx的值,因为在子程序中需要用到cx的值
mov cx,0;cx在子程序中保存一个数的位数
mov dx,0;如果除数10占8位,被除数则占16位,则商存储在al中会溢出。因此要将被除数存储在ax和dx中
mov ax, [si]
mov bx,10
t: div bx
push dx;dx中存储余数,将余数加入栈中
inc cx
mov dx,0;因为要循环,前面除法要用到dx,所以要置0
cmp ax,0;商保存在ax中,如果商为0,说明数的所有位都保存到栈中。
jne t;ax不等于0,就继续进行除法
p: mov ah,2
pop dx
add dx,30h
int 21h
loop p
pop cx
ret
printSpace:
mov ah,2
mov dl,' '
int 21h
ret
code ends
end start
- 结果
![]()
实验任务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,0
mov cx,len
call strupr
mov ah,4ch
int 21h
strupr:
s: cmp byte ptr [si],'a'
jb next
cmp byte ptr [si],'z'
ja next
mov ah,2
and byte ptr [si],11011111b
mov dl,[si]
int 21h
inc si
loop s
ret
next:
mov ah,2
mov dl,[si]
int 21h
inc si
loop s
code ends
end start
- 结果:
![]()
- 在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)
![]()
实验任务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
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 21h
over:
mov ah, 4ch
int 21h
code ends
end start
- 程序运行测试
![]()
![]()
- 程序的功能
如果程序输入的字符为7,则在屏幕指定位置输出yes;若不为7,则在屏幕指定位置输出no。
实验任务6
- task6_1.asm源代码:
assume cs:code
code segment
start:
; 42 interrupt routine install code
mov ax, cs
mov ds, ax
mov si, offset int42 ; set ds:si
mov ax, 0
mov es, ax
mov di, 200h ; set es:di
mov cx, offset int42_end - offset int42
cld
rep movsb
; set IVT(Interrupt Vector Table)
mov ax, 0
mov es, ax
mov word ptr es:[42*4], 200h
mov word ptr es:[42*4+2], 0
mov ah, 4ch
int 21h
int42:
jmp short int42_start
str db "welcome to 2049!"
len equ $ - str
; display string "welcome to 2049!"
int42_start:
mov ax, cs
mov ds, ax
mov si, 202h
mov ax, 0b800h
mov es, ax
mov di, 24*160 + 32*2
mov cx, len
s: mov al, [si]
mov es:[di], al
mov byte ptr es:[di+1], 2
inc si
add di, 2
loop s
iret
int42_end:
nop
code ends
end start
- task6_2.asm源代码:
assume cs:code
code segment
start:
int 42
mov ah, 4ch
int 21h
code ends
end start

- 通过此项实现任务,你对中断、软中断实现机制的理解
中断是通过设置中断向量与运行中断处理程序来实现的。中断向量是指中断处理程序的入口地址。这个入口地址包括段地址和偏移地址,所以一个中断向量占4个字节,高地址字存放段地址,低地址字存放偏移地址。我们可以自己编写中断处理程序对产生的中断进行处理。









浙公网安备 33010602011771号