实验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指令会改变标志寄存器的值。
 
② 在debug中调试,观察数据段中做128位加之前,和,加之后,数据段的值的变化。
答:加之前:

 

 加之后:

 

 

 

 

2.实验任务2

task2.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
① 汇编指令代码line11-18,实现的功能是?
答:从屏幕中输入一个字符,如果不是#则继续输入,是#则跳到next段
② 汇编指令代码line20-22,实现的功能是?
答:0ah是换行符的ASCII码,所以该处功能为输出换行.
③ 汇编指令代码line24-30,实现的功能是? 
答:按序输出存在数据段中的字符,#除外

  

 

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, 5

s:    push cx
    mov cx, 0
    mov al, ds:[si]
    mov ah, ds:[si + 1]
    call printNumber
    call printSpace
    pop cx
    loop s

    mov ah, 4ch
    int 21h

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

s1:    mov ah, 2
    pop dx
    or dl, 30h
    int 21h
    loop s1
    inc si
    inc si
    ret

printSpace:
    mov ah, 2
    mov dl, ' '
    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 si, offset str
    mov cx, len

s:    mov al, ds:[si]
    call strupr
    inc si
    loop s

    mov ah, 4ch
    int 21h
strupr:    cmp al,  97
    jb s1
    cmp al, 122
    ja s1
    and al, 11011111B
    jmp s1

s1:    mov ah, 2
    mov dl, al
    int 21h
    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,在屏幕的第24行第70列显示yes;如果不为7,在屏幕的第24行第70列显示no.

 

 

 

6.实验任务6

task6_1.asm
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
task6_2.asm
assume cs:code

code segment
start:
    int 42

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

截图:

 

 

 

posted @ 2021-12-13 13:03  宿于江川  阅读(19)  评论(1)    收藏  举报