实验4 8086标志寄存器及中断
四、实验结论
1、实验任务1
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的两条指令
inc si inc si inc di inc di
不能换成
add si, 2 add di, 2
理由是inc 指令不涉及进位标识符,而add指令的使用设计进位标识符,如果add指令的两项加起来超过了最大能表示的范围,则会产生进位信号。而这两项相加使用的是adc指令,adc指令是涉及到进位信号的。
但是对于本题来说是可以替换的,因为本题的si是一组数据的偏移量,每次给他加二,在本题的范围内是不会产生进位信号的,而且adc相加的两项的进位信号也是恒为0 的,所以本体不会产生影响。
以下是调试结果
2、实验任务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
运行测试截图:
回答问题:
① 汇编指令代码line11-18,实现的功能是?
读取输入的字符串,把读取的字符串放到数据段中,如果读取的事“#”符号的话,则读取结束
② 汇编指令代码line20-22,实现的功能是?
在读取到#之后执行,打印一个换行
③ 汇编指令代码line24-30,实现的功能是?
把数据段中的字符输出到屏幕中。
3、实验任务3
实验源码:
assume cs:code, ds:data data segment x dw 91, 792, 8536, 65521, 2021 len equ $ - x data ends stack segment db 16 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 16 mov si, offset x mov cx, 5 s: mov ax, ds:[si] call printNumber call printSpace add si, 2 loop s mov ah, 4ch int 21h printNumber: push cx mov cx, 0 s2: mov bx, 10 mov dx, 0 div bx push dx inc cx cmp ax, 0 jne s2 s3: pop bx or bl, 30h mov ah, 2 mov dl, bl int 21h loop s3 pop cx ret printSpace: mov ah, 2 mov dl, 20h int 21h ret code ends end start
运行测试截图:
4、实验任务4
实验源码:
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: s: cmp byte ptr [si], 'a' jb s1 cmp byte ptr [si], 'z' ja s1 sub byte ptr [si], 32 s1: inc si loop s ret code ends end start
调试截图:
5、实验任务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
运行测试截图:
程序的功能是:
读取一个字符,判断他是不是1,如果是7,就在24行70列输出yes,否则输出no
6、实验任务6
当cpu内部有某些事件发生时,会产生中断信息,比如执行int指令。cpu收到中断信息的时候,就要去执行改中断信息的处理程序。中断向量表在内存中保存,存放256个中断源对应的中断处理程序入口。
因此,只要知道中断类型码,即可以通过中断向量表得到处理程序的入口,从而执行中断处理程序。