实验4 8086标志寄存器及中断
实验任务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指令,能否替换成如下代码?你的结论的依据/理由是什么?
不能,若 si 或 di 加上 2 之后溢出,使用 add 指令时,进位标志符会被设置,影响 adc 指令。
- 在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截图。
运算过程中,没有产生进位。
实验任务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,实现的功能是?
每次读取一个字符,存放在 ds,比较字符是否为 '#',如果是,跳出循环,否则继续循环。
② 汇编指令代码line20-22,实现的功能是?
输出一个换行符。
③ 汇编指令代码line24-30,实现的功能是?
输出存储在 ds 的字符,且不输出 '#'。
实验任务3
- task3.asm源码
assume cs:code, ds:data
data segment
x dw 91, 792, 8536, 65521, 2021
len equ $ - x
data ends
stack segment
db 32 dup(0)
stack ends
code segment
start:
mov ax, stack
mov ss, ax
mov sp, 32
mov cx, len
mov ax, data
mov ds, ax
mov bx, 0
s1:
mov ax, [bx]
call printNumber
call printSpace
inc bx
inc bx
cmp bx, len
jl s1
mov ah, 4ch
int 21h
printNumber PROC NEAR
push bx
push cx
mov cx, 0
lp:
mov dx, 0
mov bx, 0ah
div bx
push dx
inc cx
cmp ax, 0
jne lp
ot:
pop bx
mov ah, 2
mov dl, bl
or dl, 30h
int 21h
loop ot
pop cx
pop bx
ret
printNumber ENDP
printSpace PROC NEAR
mov ah, 2
mov dl, ' '
int 21h
ret
printSpace ENDP
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
stack segment
db 32 dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, 020h
mov si, offset str
mov cx, len
call strupr
mov ah, 4ch
int 21h
strupr:
push ax
s1:
cmp byte ptr [si], 'a'
jb ed
cmp byte ptr [si], 'z'
ja ed
mov al, [si]
sub al, 32
mov [si], al
ed:
inc si
loop s1
pop ax
ret
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,以及输入其他字符,运行结果截图)
- 程序的功能是?
读入一个字符,若字符为'7',在屏幕24行70列显示'yes',否则显示'no'。
实验任务6
通过此项实现任务,你对中断、软中断实现机制的理解
中断分为软中断和硬中断,软中断是执行中断指令产生的,而硬中断是由外设引发的。
设置软中断分为两个步骤,复制代码和设置中断向量表。
自己选一个未被使用的中断码,实现一个中断例程,并调用测试。给出源码和运行测试截图。(选做*)
如选做,请说明你使用的中断码,并描述你实现的这个中断例程的功能。