实验4 8086标志寄存器及中断
实验任务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的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?
add si, 2 add di, 2
不能,因为使用add会对进位标志位CF产生影响,从而会影响到adc指令的执行,即标号x和y处数据的相加,而inc指令不会对CF产生影响。
② 在debug中调试,观察数据段中做128位加之前,和,加之后,数据段的值的变化。
做128位加之前:
做128位加之后:
实验任务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
运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。
① 汇编指令代码line11-18,实现的功能是?
从键盘上输入一串字符,以#结束,跳转到next段继续执行。
② 汇编指令代码line20-22,实现的功能是?
输出一个换行符。
③ 汇编指令代码line24-30,实现的功能是?
将输入的一串字符,完整打印输出出来。
实验任务3
assume cs:code,ds:data,ss:stack data segment x dw 91,792,8536,65521,2021 len equ $ - x data ends stack segment dw 8 dup(0) stack ends code segment start: mov ax,data mov ds,ax mov ax,stack mov ss,ax mov sp,16 mov si,0 mov cx,len/2 s0: mov ax,[si] mov dx,0 push cx call printNumber call printSpace pop cx inc si inc si loop s0 mov ah,4ch int 21h printNumber: mov cx,0 flag1: mov bx,10 mov dx,0 div bx push dx inc cx cmp ax,0 jne flag1 s1: pop dx mov ah,2 or dl,30h int 21h loop s1 ret printSpace: mov ah,2 mov dl,' ' int 21h ret code ends end startassume cs:code,ds:data,ss:stack data segment x dw 91,792,8536,65521,2021 len equ $ - x data ends stack segment dw 8 dup(0) stack ends code segment start: mov ax,data mov ds,ax mov ax,stack mov ss,ax mov sp,16 mov si,0 mov cx,len/2 s0: mov ax,[si] mov dx,0 push cx call printNumber call printSpace pop cx inc si inc si loop s0 mov ah,4ch int 21h printNumber: mov cx,0 flag1: mov bx,10 mov dx,0 div bx push dx inc cx cmp ax,0 jne flag1 s1: pop dx mov ah,2 or dl,30h int 21h loop s1 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 code segment start: mov ax,data mov ds,ax mov si,0 mov cx,len call strupr mov ax,4c00h int 21h strupr: s0: mov al,[si] cmp al,97 jb s1 cmp al,122 ja s1 and al,11011111B mov [si],al s1: inc si loop s0 ret code ends end start
在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值):
实验任务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 ; 设置光标位置在第24行 mov dl, 70 ; 设置光标位置在第70列 int 10h ; 设置光标位置 cmp al, '7' je s1 mov ah, 9 mov dx, offset str2 int 21h ; 显示标号str2处的字符串 jmp over s1: mov ah, 9 mov dx, offset str1 int 21h ; 显示标号str2处的字符串 over: mov ah, 4ch int 21h code ends end start
功能:
判断输入的字符是否是‘7’,如果是,则在屏幕第24行第70列输出‘yes’;如果不是,则在屏幕第24行第70列输出‘no’。
实验任务6
实验结果如上图所示
通过此项实现任务,你对中断、软中断实现机制的理解:
硬中断:键盘鼠标这些输入都会触发中断。
软中断:系统调用产生的中断。