实验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]
    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

2.问题

line31~line344inc指令,能否替换成如下代码?你的结论的依据/理由是什么?

add si, 2
add di, 2

不能。因为两次inc指令不会改变标识符CF,而add指令可能会改变标识符CF。

验证:

(1)连续两次inc ax

 

 

 (2)add ax,2

 

 

  通过对比可以发现,add会对CF产生影响,这有可能在实现多进制加法时多加1。

3.问题

debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截图

(1)做加法前:

 

 (2)做加法后:

 

 

任务2

1.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, 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,实现的功能是?

答:读入输入的字符。判断如果是"#"则跳转到"next"函数处执行,否则继续读入下一个字符串。

② 汇编指令代码line20-22,实现的功能是?

答:实现换行功能。

③ 汇编指令代码line24-30,实现的功能是?

答:输出除"#"以外先前输入的字符串。

 

任务3

1.task3.asm源码:

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

stack segment
    db 64 dup(0)
    top equ $+1
stack ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,stack
    mov ss,ax
    mov sp,top

    mov cx,len/2
    mov bx,0
s1:
    mov ax,ds:[bx]
    push bx
    push cx
    call printNumber
    call printSpace
    pop cx
    pop bx
    add bx,2
    loop s1

    mov ah,4ch
    int 21h

printNumber:
    mov bx,10
    mov cx,0
s2:
    mov dx,0
    div bx
    push dx
    inc cx
    cmp ax,0
    jne s2

s3:
    mov ah,2
    pop dx
    or dl,30h
    int 21h
    loop s3
    ret

printSpace:
    mov ah,2
    mov dl,20h
    int 21h
    ret

code ends
end start

运行结果

 

 

任务4

1.task4.asm源码:

assume cs:code,ds:data
data segment
    str db "assembly language, it's not difficult but tedious"
    len = ($ - str)
data ends

stack segment
    db 128 dup(0)
    top equ $ + 1
stack ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,stack
    mov ss,ax
    mov sp,top

    mov si,0
    mov cx,len
    call strupr
    mov ah,4ch
    int 21h
strupr:
s:
    cmp byte ptr ds:[si],61h
    jb s1
    cmp byte ptr ds:[si],7ah
    ja s1
    mov dl,ds:[si]
    and dl,11011111B
    mov ds:[si],dl
s1:
    inc si
    loop s
    ret
code ends
end start

问题

debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)

(1)调用前数据段的值:

 

 (2)调用后数据段的值:

 

 

任务5

1.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 dx, offset str1
    int 21h                 ; 显示标号str2处的字符串

    over:
        mov ah, 4ch
        int 21h
code ends
end start

运行结果

输入7

 

 输入其它字符

 

 程序的功能

答:判断当前输入的字符是否是7,如果是在光标第70行出输出yes,否则在光标第24行输出no。

任务6

对中断,软中断实现机制的理解

(1)中断:当中断源发出中断信号时,CPU暂定当前的程序,转而去执行其它的程序,这个流程称为中断。中断可以通过改变CS:IP来实现。

(2)软中断:软中断是CPU内部产生的中断信号,比如除法溢出,或者调用中断例程,其实现方式和call类似

posted @ 2021-12-16 23:17  sdddy  阅读(44)  评论(0编辑  收藏  举报