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

1.实验任务

验证性实验:有些汇编指令会影响到标志寄存器中的一个或多个状态标志位。
在debug环境中,分别实践、观察:
① add指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?
② inc指令对标志寄存器中的零标志位ZF(Zero Flag)、进位标志位CF(Carry Flag)是否有影响?

add对ZF和CF都造成了影响

 inc只对ZF造成了影响

 

 

 

2.实验任务2

使用任意文本编辑器,录入8086汇编源码task2.asm。
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

1.line11-line18的作用是判断输入字符是否等于#,若等于,则跳转到next,若不相等,则一直循环s1。

2.line20-22的作用是输出换行字符,因为此时输入结束

3.line24-30的作用是将字符个数赋值给cx,不断循环s2,在电脑上输出。

3.实验任务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
s:  mov ax, [si]
    call printNumber
    call printSpace
    inc si
    inc si
    loop s
    mov ax, 4c00h
    int 21h

printNumber:
    push cx
    mov cx, 0

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

    mov ah, 2
 s2:pop dx
    add dx, 48
    int 21h
    loop s2

    pop cx
    ret

printSpace:
    mov ah, 2
    mov dl, 20h
    int 21h
    ret
code ends
end start

 

 4.实验任务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 cx, len
    mov si, 0

    call strupr

    mov ax, 4c00h
    int 21h

strupr:
s:
    mov al, [si]
    cmp al, 'a'
    jb next
    cmp al, 'z'
    ja next
    sub al, 32
    mov [si], al
next:
    inc si
    loop s
    ret

code ends
end start

 

 5.实验任务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
    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

6.实验6

assume cs:code

code segment
start:
    ; 42 interrupt routine install code
    mov ax, cs
    mov ds, ax
    mov si, offset int42  ; set ds:si

    mov ax, 0
    mov es, ax
    mov di, 200h        ; set es:di

    mov cx, offset int42_end - offset int42
    cld
    rep movsb

    ; set IVT(Interrupt Vector Table)
    mov ax, 0
    mov es, ax
    mov word ptr es:[42*4], 200h
    mov word ptr es:[42*4+2], 0

    mov ah, 4ch
    int 21h

int42:
    jmp short int42_start
    str db "welcome to 2049!"
    len equ $ - str

    ; display string "welcome to 2049!"
int42_start:
    mov ax, cs
    mov ds, ax
    mov si, 202h

    mov ax, 0b800h
    mov es, ax
    mov di, 24*160 + 32*2

    mov cx, len
s:  mov al, [si]
    mov es:[di], al
    mov byte ptr es:[di+1], 2
    inc si
    add di, 2
    loop s

    iret
int42_end:
   nop
code ends
end start

 

assume cs:code

code segment
start:
    int 42

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

 

 

posted @ 2021-12-16 21:30  boyridingpig  阅读(56)  评论(3)    收藏  举报