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

实验一

源码:

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

    add si, 2
    add di, 2
    ; inc si
    ; inc si
    ; inc di
    ; inc di
    loop s

    pop di
    pop si
    pop cx
    pop ax
    ret
code ends
end start

可以替换 add si, 2

语义上,他们做的事情相同,经过实验验证,修改前后程序运行结果不变。

截图:

实验二

源码:

assume cs:code, ds:data
data segment
        db 80 dup(0)
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-18,实现的功能是

不断读入一个字符,存入 data 段,直到读入一个 # 停止。

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

换行。

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

输出之前存储的输入字符。

实验三

源码:

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
; args
;    ax input
printNumber:
    cmp ax, 0
    jne pnmain    
    ret
pnmain:
    mov dx, 0
    mov bx, 10
    div bx

    push dx
    call printNumber

    mov ah, 2
    pop bx
    mov dl, bl
    add dl, '0'
    int 21h
    ret
printSpace:
    mov dl, ' '
    mov ah, 2
    int 21h
    ret
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, ss:[16]

    mov cx, len/2
    mov si, offset x
lp: mov ax, 0
    mov ax, word ptr [si]
    call printNumber
    call printSpace
    add si, 2
    loop lp

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

截图:

实验四

源码:

assume cs:code, ds:data

data segment
    string db "assembly language, it's not difficult but tedious"
    len equ $ - string
data ends

stack segment
    db 16 dup(0)
stack ends

code segment
; (ds:si) 字符串首地址的段地址和偏移地址分别送至ds和si
; (cx) 字符串的长度
strupr:
    mov bp, 0
    ; ds:[si+di] >= 'a' and <= 'z'
lp: mov al, byte ptr ds:[si+bp]
    cmp al, 'a'
    jl skip
    cmp al, 'z'
    jg skip
    
    add al, 'A' - 'a'
    mov byte ptr ds:[si+bp], al
skip:
    inc bp
    loop lp
    ret
    
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, ss:[16]

    mov si, 0
    mov cx, len
    call strupr

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

截图:

实验五

源码:

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。

posted @ 2021-12-16 15:01  fitenne  阅读(46)  评论(4)    收藏  举报