10.22汇编

Posted on Oct 22, 2020

今天看完了int指令和端口,由于这些知识和32位的有一定区别,所以知识点就不列了,我也只是粗略的看了一下,做了一下实验而已

实验13

assume cs:code,ds:data

data segment
    db 'welcome to masm!',0
data ends

stack segment
     dd 8 dup(0)
stack ends

code segment
main:
    ;---------------------------------setup inter7ch---------------------------------
    mov ax,0
    mov es,ax
    mov ax,cs
    mov ds,ax
    mov cx,offset end_of_inter7ch-inter7ch
    mov si,offset inter7ch
    mov di,200h
    cld
    rep movsb
    ;set err vector
    mov ax,0
    mov es,ax
    mov es:[7ch*4+0],word ptr 200h
    mov es:[7ch*4+2],word ptr 0h
    ;---------------------------------setup inter7ch---------------------------------
    mov dh,10
    mov dl,10
    mov cl,2
    mov ax,data
    mov ds,ax
    mov ax,stack
    mov ss,ax
    mov sp,32
    mov si,0
    int 7ch
    mov ax,4c00h
    int 21h

inter7ch:
    push ax
    push bx
    push di
    ;------------------------------clear the screen------------------------------
    push cx
    push bx
    mov bx,0b800h
    mov es,bx
    mov bx,0
    mov cx,2000
    s_clear:
        mov word ptr es:[bx],0
        add bx,2
    loop s_clear
    pop bx
    pop cx
    ;------------------------------clear the screen------------------------------
    ;--------------------------dispaly error information-------------------------
    mov ax,0b800h
    mov es,ax
    mov ax,160
    mul dh
    add al,dl
    adc ah,0
    add al,dl
    adc ah,0
    mov di,ax
    mov ah,cl
    mov ch,0
    mov cl,ds:[si]
    s0_inter7ch:
        jcxz end_loop_inter7ch
        mov al,ds:[si]
        mov es:[di].0,al
        mov es:[di].1,ah
        inc si
        add di,2
        mov cl,al
    jmp short s0_inter7ch
    end_loop_inter7ch:

    pop di
    pop bx
    pop ax
iret
end_of_inter7ch:nop
code ends

end main

实验14

assume cs:code

code segment
main:
    ;------------------------------clear the screen------------------------------
    mov bx,0b800h
    mov es,bx
    mov bx,0
    mov cx,2000
    s_clear:
        mov word ptr es:[bx],0
        add bx,2
    loop s_clear
    ;------------------------------clear the screen------------------------------
    loop_main:
    mov ax,0b800h
    mov es,ax
    mov di,0
    ;year
    mov al,9
    mov dx,070h;input from CMOS
    out dx,al
    mov dx,071h;input from CMOS
    in al,dx
    mov ah,al
    and ah,11110000b
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,48
    add al,48
    mov dx,2
    mov es:[di].0,ah
    mov es:[di].1,dx
    add di,2
    mov es:[di].0,al
    mov es:[di].1,dx
    add di,2

    mov al,'/'
    mov es:[di].0,al
    mov ah,00000111b
    mov es:[di].1,ah
    add di,2
    ;month
    mov al,8
    mov dx,070h;input from CMOS
    out dx,al
    mov dx,071h;input from CMOS
    in al,dx
    mov ah,al
    and ah,11110000b
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,48
    add al,48
    mov dx,2
    mov es:[di].0,ah
    mov es:[di].1,dx
    add di,2
    mov es:[di].0,al
    mov es:[di].1,dx
    add di,2

    mov al,'/'
    mov es:[di].0,al
    mov ah,00000111b
    mov es:[di].1,ah
    add di,2
    ;day
    mov al,7
    mov dx,070h;input from CMOS
    out dx,al
    mov dx,071h;input from CMOS
    in al,dx
    mov ah,al
    and ah,11110000b
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,48
    add al,48
    mov dx,2
    mov es:[di].0,ah
    mov es:[di].1,dx
    add di,2
    mov es:[di].0,al
    mov es:[di].1,dx
    add di,2

    mov al,' '
    mov es:[di].0,al
    mov ah,00000111b
    mov es:[di].1,ah
    add di,2
    ;hour
    mov al,4
    mov dx,070h;input from CMOS
    out dx,al
    mov dx,071h;input from CMOS
    in al,dx
    mov ah,al
    and ah,11110000b
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,48
    add al,48
    mov dx,2
    mov es:[di].0,ah
    mov es:[di].1,dx
    add di,2
    mov es:[di].0,al
    mov es:[di].1,dx
    add di,2

    mov al,':'
    mov es:[di].0,al
    mov ah,00000111b
    mov es:[di].1,ah
    add di,2
    ;minutes
    mov al,2
    mov dx,070h;input from CMOS
    out dx,al
    mov dx,071h;input from CMOS
    in al,dx
    mov ah,al
    and ah,11110000b
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,48
    add al,48
    mov dx,2
    mov es:[di].0,ah
    mov es:[di].1,dx
    add di,2
    mov es:[di].0,al
    mov es:[di].1,dx
    add di,2

    mov al,':'
    mov es:[di].0,al
    mov ah,00000111b
    mov es:[di].1,ah
    add di,2
    ;second
    mov al,0
    mov dx,070h;input from CMOS
    out dx,al
    mov dx,071h;input from CMOS
    in al,dx
    mov ah,al
    and ah,11110000b
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,48
    add al,48
    mov dx,2
    mov es:[di].0,ah
    mov es:[di].1,dx
    add di,2
    mov es:[di].0,al
    mov es:[di].1,dx
    add di,2

    jmp near ptr loop_main
    ;mov ax,4c00h
    ;int 21h
code ends

end main