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

 

 

    

      执行后ZF和CF的值置为1

 

     

      执行后ZF的值置为1

 

 

   有些指令的执行结果会影响到一些标志位,如指令add/sub的执行会影响到CF, PF, AF, ZF, SF, OF; 有些,则不影响,如mov, push, pop, inc, dec。

  inc不改变标志位CF,而add则改变CF

 

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指令会改变CF标志位

数据段x的数据与数据段y的数据做128位加之后,结果保存在数据段x的原有数据的位置上。

 

 

 

 

运行并测试程序:

             

①从键盘读取一窜字符,直到读到“#”为止

②实现换行的功能

③将输入的字符串输出到屏幕上

 

 

 task3.asm:

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 di, offset x
    mov cx,len    
    mov bx ,10

 s1:
    mov ax,word ptr ds:[di]
    call printNumber
    call printSpace
    inc di
    inc di
    dec cx
    loop s1

    mov ah ,4ch
    int 21h

    printNumber: 
      push cx
      mov cx,0
s0:      
      sub ax, 0
       jz s3    
       mov dx,0
       div bx
       push dx
       inc cx
       jmp s0

    s3:pop dx 
        or dl , 30h
        mov ah , 2
        int 21h
        loop s3

       pop cx
        ret

    printSpace:
        mov ah , 2
        mov dl , ' '
        int 21h
        ret

code ends
end start

运行结果:

 

 

 

 

 

代码实现:

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
s1:
    call strupr
    mov bl,al
    mov dl , bl
    mov ah,2
    int 21h
    inc si
    loop s1

    mov ah ,4ch
    int 21h

strupr:
    mov al,ds:[si]
    cmp al,'a'
    jb next
    cmp al,'z'
    ja next
    sub al,20h
next:
    ret

code ends
end start

运行并测试程序:

 

转换成功!

 

运行并测试代码:

 

 

 

代码功能:从键盘读取一个字符,如果字符是‘7’,则在屏幕输出str1处的字符串”Yes“,反之输出位于str2的字符串”No“

 

 

 

 

 

 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-16 10:55  melons  阅读(53)  评论(2编辑  收藏  举报