实验4 8086标志寄存器及中断
实验任务1
①
对ZF和CF标志位均有影响

②
对ZF标志位有影响,但是对CF标志位没有影响

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
①不能替换为add si,2与add di,2 因为会影响到多个标志位,而inc是不会影响到的
②调试截图如下:


实验任务2
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

答:
Line 11-18
接收键盘上输入的字符,与#进行比较,如果遇到#则进入next子功能
Line 20-22
在屏幕上输出换行符
Line 24-30
在屏幕上输出存放在数据段中的字符
实验任务3
assume ds:data, cs:code, ss:stack data segment x dw 91, 792, 8536, 65535, 2021, 0 len equ $ - x data ends stack segment dw 8 dup(?) stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 16 mov cx, len/2 s: mov ax, word ptr ds:[di] add di, 2 push cx call printNumber call printSpace pop cx loop s mov ah, 4ch int 21h printNumber: mov bx, 0 s1: mov bp, 10 mov dx, 0 div bp push dx inc bx mov cx, ax inc cx loop s1 mov cx, bx s2: pop dx add dl, 30h mov ah, 2 int 21h loop s2 ret printSpace: mov ah, 2 mov dl, ' ' int 21h ret code ends end start

实验任务4
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 8 dup(?) stack ends code segment start: mov ax, data mov ds, ax mov si, 0 mov cx, len call strupr call printStr mov ax, 4c00h int 21h strupr: push cx push si s: mov al, ds:[si] cmp al, 97 jl c cmp al, 122 jg c and al, 0dfh mov ds:[si], al c: inc si loop s pop si pop cx ret printStr: push cx push si s2: mov ah, 2 mov dl, ds:[si] int 21h inc si loop s2 pop si pop cx ret code ends end start
call strpur调用前
调用后

运行截图:

实验任务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进行比较
如果相同
则在第24行第70列输出数据段的str1标号处数据yes
如果不相同
则在第24行第70列输出数据段的str2标号处数据no
实验任务6

对于中断、软中断实现机制的理解
答:
中断也是异常的一种,中断有硬中断(由硬件产生的中断)和软中断(软件产生的中断)之分。ARM有七种不同的中断源,在中断向量表中对应的地址范围是0X00 ~ 0X1C
软件中断是内部中断的一种,是由软件引起的非屏蔽型中断
其中软中断的处理过程为
(1)将标志寄存器压入堆栈。
(2)用清中断标志(IF)和单步标志(TF)禁止硬件中断,即关中断。
所以当我们自己编制中断服务程序时,在程序内必要时可以开中断,即打开由硬件自动关闭的中断允许触发器,使之能够响应更高级的中断。
(3)将当前代码段寄存器的内容(CS)压入栈。
(4)将当前指令指针(IP)压入栈。
步骤(3)、(4)的目的是要确保中断处理完毕之后能够正确地返回中断调用者。
(5)转向中断服务程序入口并将控制交给中断服务程序。
在中断服务程序执行完后,即CPU接收到IRET指令时,它又将产生以下步骤:
(1)弹出IP:从堆栈中将保存的指令指针IP由堆栈弹出到IP中。
(2)弹出CS:将保存的段寄存器内容由堆栈弹出到代码段寄存器中。
(3)恢复标志寄存器
实验总结
1、CF代表运行或左移时产生的进位,如果有进位,CF为1 进位标志位。ZF 零标志位,除进位外,首位是否为0。
2、add/sub也会影响到多个标志位,cmp mov push pop inc dec 就不影响。有些汇编指令执行时,会依赖于标志位的值
3、mov al,0ffh
add al,1
mov ah,0
adc ah,0
代表将丢掉的进位补充进来
就等同于
mov ax,0ffh
add ax,1
实验任务1
① 不能替换为add si,2与add di,2 因为会影响到多个标志位,而inc是不会影响到的
ds:si 076A:0000
ds:di 076A:0010
浙公网安备 33010602011771号