实验4 8086标志寄存器及中断
test01.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
回答问题:
1.2.1 add指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?
实验结果截图:

1.2.1.2
分析:--加法指令作为算数运算指令,运算结果将会影响状态标志位,除了INC指令不会影响到位CF,其余指令都会影响到标识位CF和ZF
--进一步地,ZF位从NZ变成了ZR,即就是表示运算结果为0;而CF位从NC变成了CY,从0到1的变化表示进借位发生改变,即表示运算中最高位向更高位产生了进位;
1.2.2 INC指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?
实验截图:

1.2.2.2
分析:-- 形如INC OPR的指令本身的任务是,将制定操作数加一;故而,INC本身是不会改变标志位CF的
-- 相反地,零标志位ZF发生了改变:ZF位从NZ变为ZR,即就是表示运算结果位0,表示运算结果不为0
任务2:
task2源码:
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
结果截图:

回答问题
1.line11-18,实现的功能是接收从键盘上输入的一串字符,以#结束。
2.line20-22,实现的功能是输出ASCII码为0a(h)的字符,即换行符。
3.line24-30,实现的功能是依次输出先前接收的字符串(#除外)。
任务3:
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 cx,5
mov si,0
s1: mov ax,word ptr ds:[si]
add si,2
push cx
call printNumber
call printSpace
pop cx
loop s1
mov ah,4ch
int 21h
printNumber:
mov dx,0
mov cx,0
s2: mov bx,10
div bx
push dx
mov dx,0
inc cx
add ax,0
jnz s2
s3: pop dx
add dl,30h
mov ah,2
int 21h
loop s3
ret
printSpace:
mov ah,2
mov dl,20h
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, offset str
mov cx, len
call strupr
mov ah, 4ch
int 21h
strupr:
s1: mov al,ds:[si]
cmp al,'a'
jb s2
cmp al,'z'
ja s2
and al,0dfh
mov ds:[si],al
s2: inc si
loop s1
ret
code ends
end start
调用前:

调用后:

任务5:
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,不是则输出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 ; 调用自己实现的42号软中断 mov ah, 4ch int 21h code ends end start
对汇编源程序task6_1.asm进行汇编、链接,得到可执行程序task6_1.exe。运行task6_1.exe,实现将
42号中断处理程序安装到0:200开始的连续内存空间,并设置中断向量表,使得将来通过 int 42 ,系统
可以跳转到中断处理程序。
对汇编源程序task6_2.asm进行汇编、链接,得到可执行程序task6_2.exe。运行task6_2.exe。
两个程序正确编写、汇编、链接,运行后,预期结果如下:

通过此项实现任务,你对中断、软中断的理解
自己选一个未被使用的中断码,实现一个中断例程,并调用测试。给出源码和运行测试截图。(选做*)
8086一共提供了256个中断,中断码为0~255,其中,有些保留作为系统用,有些未使用。可以自
行挑选一个未被使用的中断码,程时自己编写中断例程。
运行结果:

中断:CPU在接收到外部发送的或内部产生的一种特殊信息时,会立即处理特殊信息。
软中断:CPU内部产生特殊信息(如除法错误、单步执行、执行into指令和执行int指令)时,立即处理该情况。

浙公网安备 33010602011771号