端口(学习汇编)
1.在访问端口的时候,CPU通过端口地址来定位端口。因为端口所在的芯片和CPU通过总线相连,所以,端口地址和内存地址一样,通过地址总线来传送。
2.在PC系统中,CPU最多可以定位64KB个不同的端口,则端口地址的范围为0~65535
3.对端口的读写不能用mov,push、pop等内存读写指令。端口的读写指令只有两条:in和out,分别用于从端口读写数据和往端口写入数据。
4.在in和out指令中,只能使用ax或al来存放从端口中读入的数据或要发送到端口中的数据。
5.访问8位端口时用al,访问16位端口时用ax。
6.对0~255以内的端口进行读写时:
in al,20h ;从20h端口读入一个字节
out 20h,al ;往20h端口写入一个字节
7.对256~65535的端口进行读写时,端口号放在dx中:
mov dx,3f8h ;将端口号3f8h送入dx
int al,dx ;从3f8h端口读入一个字节
out dx,al ;向3f8h端口写入一个字节
shl和shr指令
1.shl是逻辑左移指令,它的功能为:
1)将一个寄存器或内存单元中的数据向左移位;
2)将最后移出的一位写入CF中;
3)最低位用0补充。
2.shr是逻辑右移指令,它和shl所进行的操作刚好相反。
1)将一个寄存器或内存单元中的数据向右移位;
2)将最后移出的一位写入CF中;
3)最高位用0补充。
3.如果移动位数大于1时,必须将移动位数放到cl中。如果只移动一位,则可以直接写出来。
4.将X逻辑左移一位,相当于执行X=X*2,将X逻辑右移一位,相当于执行X=X/2。
CMOS RAM 中存储的时间信息
1.在CMOS RAM中,存放着当前的时间:年、月、日、时、分、秒。这6个信息的长度都为1个字节,存放单元为:
秒:0 分:2 时:4 日:7 月:8 年:9
这些数据以BCD码的方式存放。BCD码是以4位二进制数表示十进制码的编码方法。
2.一个字节可表示两个BCD码。则CMOS RAM存储时间信息的单元中,存储了用两个BCD码表示的两位十进制数,高4位的BCD码表示十位,低4位的BCD码表示个位。
3.BCD码值=十进制数码值,则BCD码值+30h=十进制数对应的ASCII码。
自己写的一个显示当前时间,日期汇编程序:
assume cs : codesg, ss : stacksg
stacksg segment
    dw 16 dup (0)
stacksg ends
codesg segment
start:    
	mov al, 9	          	;year
    out 70h, al
    in al, 71h
    mov bx, 0b800h
    mov ds, bx	          ;25*80
    mov si, 160 * 24 + 0 * 2     ;每个字符占2个字节,n*2确定列坐标
    mov bl, al	          			   ;此时在25行0列
    mov cl, 4
    and bl, 00001111b
    shr al, cl
    add bl, 30h    
    add al, 30h
    mov ah, al
    mov al, bl
    mov bl, ah
    mov [si], bl
    mov byte ptr [si + 1], 0cah 
    add si, 2
    mov [si], al
    mov byte ptr [si + 1], 0cah 
    add si, 2
    mov byte ptr [si], '/'
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov al, 8	          		;month
    out 70h, al
    in al, 71h
    mov bl, al
    mov cl, 4
    and bl, 00001111b
    shr al, cl
    add bl, 30h
    add al, 30h
    mov ah, al
    mov al, bl
    mov bl, ah
    mov [si], bl
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov [si], al
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov byte ptr [si], '/'
    mov byte ptr [si + 1], 0cah
    add si, 2
    
    mov al, 7          			;day
    out 70h, al
    in al, 71h
    mov bl, al
    mov cl, 4
    and bl, 00001111b
    shr al, cl
    add bl, 30h
    add al, 30h   
    mov ah, al
    mov al, bl
    mov bl, ah
    mov [si], bl
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov [si], al
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov byte ptr [si], ' '
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov al, 4          			;hour
    out 70h, al
    in al, 71h   
    mov bl, al
    mov cl, 4
    and bl, 00001111b
    shr al, cl
    add bl, 30h
    add al, 30h   
    mov ah, al
    mov al, bl
    mov bl, ah
    mov [si], bl
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov [si], al
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov byte ptr [si], ':'
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov al, 2	          		;minute
    out 70h, al
    in al, 71h
    mov bl, al
    mov cl, 4
    and bl, 00001111b
    shr al, cl
    add bl, 30h
    add al, 30h 
    mov ah, al
    mov al, bl
    mov bl, ah
    mov [si], bl
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov [si], al
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov byte ptr [si], ':'
    mov byte ptr [si + 1], 0cah
    add si, 2
    
    mov al, 0	          		;second
    out 70h, al
    in al, 71h
    mov bl, al
    mov cl, 4
    and bl, 00001111b
    shr al, cl
    add bl, 30h
    add al, 30h
    mov ah, al
    mov al, bl
    mov bl, ah
    mov [si], bl
    mov byte ptr [si + 1], 0cah
    add si, 2
    mov [si], al
    mov byte ptr [si + 1], 0cah
    add si, 2
	jmp near ptr start        ;不停刷新时间
    
    mov ax, 4c00h
    int 21h
codesg ends 
end start
 
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号