实验4 8086标志寄存器及中断

1. 实验任务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
复制代码

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

add si, 2
add di, 2

解:不可以,add指令会对标志位ZF和CF产生影响,inc指令只会对ZF位产生影响, 对CF位不会产生影响

 

② 在debug中调试,观察数据段中做128位加之前,和,加之后,数据段的值的变化。

加之前:

 

 加之后:

 

 

 

2. 实验任务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, 0
s2:     mov ah, 2
        mov dl, [si]
        int 21h
        inc si
        loop s2

        mov ah, 4ch
        int 21h
code ends
end start
复制代码

 对源程序task2.asm进行汇编、链接,得到可执行文件task2.exe。 运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。结合运 行结果,理解代码并回答问题:

① 汇编指令代码line11-18,实现的功能是?

读取输入内容,当输入为‘#’时跳转到next

 

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

输出换行

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

输出#前的字符串

3. 实验任务3

task3.asm源码 :

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 cx,len
   mov si,offset x
s:
   mov ax,ds:[si]
   call printNumber
   call printSpace
   inc si
   inc si
   loop s

   mov ah,4ch
   int 21h
printNumber:
   mov bx,0AH
   mov dx,0
   mov di,0
   push cx
s1:
   div bx
   push dx
   inc di
   mov dx,0
   cmp ax,0
   je next
   jmp s1
next:
   mov ah,2
   mov cx,di
s2:
   pop dx
   or dl,30H
   int 21h
   loop s2

   pop cx
   ret
printSpace:
    mov dl,' '
    mov ah,2
    int 21h
    ret
code ends
end start

运行测试截图 :

 

 

 

4. 实验任务4

task4.asm源码 :

复制代码
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
    call upper
    mov ah, 4ch
        int 21h
upper:
    mov cx,len
    s:    mov dl,ds:[si]
        cmp dl,61h
        jb s1
        cmp dl,7ah
        ja s1
        and dl,110111111
    s1:    mov ah,2
        int 21h
        inc si
        loop s
    ret
code ends
end start
复制代码

运行测试截图 :

 

 

 

5. 实验任务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
    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,则输出yes;否则输出no。

6. 实验任务6

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

中断被触发后,cpu将通过寄存器执行内存中指定位置的程序(中断处理程序)。中断处理一般由操作系统完成,操作系统Trap()函数将保存中断现场,并通过不同的中断执行不同的策略。

posted @ 2021-12-16 23:21  trionfordring  阅读(49)  评论(3编辑  收藏  举报