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

1. 实验任务1

  • task4_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

  • add对ZF、CF会有影响,而inc对CF不会有影响。

  • 不能,add指令会影响CF,进而影响adc指令的执行。

  • 执行前:

执行后:

2. 实验任务2

  • task4_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
  • 运行结果截图

  • 11-18

持续接受从键盘上键入的字符,存入数据段中,直到键入‘#’。

  • 20-22

若键入‘#’,打印一个换行符。

  • 24-30

将数据段中的内容即先前键入的符号输出到屏幕上。

3. 实验任务3

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

code segment
    start:      
                mov  ax,data
                mov  ds,ax

                mov  si,offset x

                
                mov  cx,len/2

                s2:mov ax,[si]
                call printNumber
                inc si
                
                inc si
                
                loop s2
 

                mov  ax,4c00h
                int  21h

    printNumber:
                push cx

                mov cx,0
                s3:
                mov dx,0
                mov di,0000000ah
                
                div di
                
                push dx
                inc cx

                cmp ax,0
                je p1

                jmp s3
                
                p1:
                pop ax
                mov dl,al
                mov ah,2
                or dl,30h
                int 21h
                loop p1

            

                s1:call printSpace
                pop cx
                ret

                
                

    
      

                

    printSpace: 
                mov ah,2

                mov  dl,' '
	            int  21h
	            ret


code ends
end start
  • 运行截图:

4.实验任务4

  • task4_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 ax,4c00h
    int 21h

strupr:
    mov al,[si]
    
    
    cmp al,'a'
    jl s
    cmp al,'z'
    jg s
    
    sub al,32
    s:
    mov ah,2
    mov dl,al
    int 21h
   
    inc si
    loop strupr
    
    ret
    

code ends
end start


  • 调用前

  • 执行截图

5.实验任务5

  • task4_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

6.实验任务6

  • cpu在取得中断类型码后,需要将标志寄存器和当前指令的地址入栈,设置TF、IF为0,然后根据中断类型码在中断向量表中获取处理程序的入口地址,执行完处理程序后,恢复用到的寄存器并使用iref返回。
posted on 2021-12-14 00:17  憖叇苝歏  阅读(55)  评论(1)    收藏  举报