实验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]
    add 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进位标志位。

②在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
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,实现的功能是?
从键盘上输入单个字符,判断输入字符是否为‘#’,如果不是,将其存入数据段偏移地址为si的位置,直到输入字符为#时,跳转到next标号处。
② 汇编指令代码line20-22,实现的功能是?
mov ah,2是字符输出功能,要输出的字符放在dl中,0ah是换行符的ASCII码,实现了换行的功能。
③ 汇编指令代码line24-30,实现的功能是?
mov ah,2是字符输出功能,要输出的字符放在dl中,实现了循环输出si存放的字符。

实验任务3

task3.asm源码

assume cs:code,ds:data
data segment
    x dw 91,792,8536,65521,2021
data ends

stack segment
    db 16 dup(0)
code segment
start:
    mov ax,data
    mov ds,ax

    mov si,offset x
    mov cx,5
s:
    mov ax,[si]
    call printNumber
    call printSpace

    inc si
    inc si
    loop s

    mov ah,4ch
    int 21h
printNumber:
    push bx
    push di
    push cx
    mov cx,0
    mov dl,0
s:
    mov dx,0
    mov bx,10
    div bx
    or dl,30h
    push bx
    inc di
    cmp ax,0
    jne s1
    mov cx,di
s2:
    pop dx
    mov ah,2
    int 21h
    loop s2

    pop cx
    pop di
    pop bx

    ret

printSpace:
    mov dl,' '
    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 = $ - str
data ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov si,0
    mov cx,len
    call strupr
    mov ah,4ch
    int 21h
 
s:
    cmp byte ptr ds:[si],61h
    jb s2
    cmp byte ptr ds:[si],7ah
    ja s2
    mov dl,ds:[si]
    and dl,11011111B
    mov ds:[si],dl
s2:
    inc si
    loop s
    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    ;光标位置放在第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 ds,offset str1
    int 21h    ;显示标号str1处的字符串
over:
    mov ah,4ch
    int 21h
code ends
end start

 

程序运行测试截图

 

程序的功能是?

若输入字符为7,则显示“yes”;若输入的字符不为“7”,则显示“no”

实验任务6

通过此项实验任务,你对中断、软中断实现机制的理解

中断是异常的一种,中断就是使CPU暂时挂起当前正在进行的工作并转向某紧急事件的服务与处理程序。

软中断是内部中断的一种,CPU执行int n指令时立即产生一个软件中断,中断的类型由指令中的n指明。

中断过程为:先取得中断类型码,再将标志寄存器的值入栈,设置TF和IF为0,再将CS和IP入栈,从[n*4]和[n*4+2]获取CS和IP的值。

posted @ 2021-12-13 21:23  荷月十四  阅读(48)  评论(2编辑  收藏  举报