0%

汇编:实验14:从CMOS读取并显示时间

从 CMOS RAM 读取时间并显示到屏幕。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; 显示CMOS中当前日期时间
assume cs:code
code segment
src:
db 9,8,7,4,2,0 ; 年月日时分秒的地址
dst:
db 'yy/mm/dd hh:mm:ss',0

start:
mov ax,cs
mov ds,ax
mov si,offset src
mov di,offset dst
mov cx,6
s:
mov dx,cx
mov al,[si]
out 70h,al ; 70h为地址端口
in al,71h ; 71h为数据端口
mov ah,al
mov cl,4
shr ah,cl ; 右移4位,ah为十进制的十位数
and al,00001111b ; al为十进制的个位数
add ah,30h
add al,30h ; 数值转字符形式
xor ah,al
xor al,ah
xor ah,al ; 交换ah al的值
mov [di],ax
add di,3
inc si
mov cx,dx
loop s

mov ax,0b800h
mov es,ax
mov di,0
mov si,offset dst
s1:
mov ch,0
mov cl,[si]
jcxz ok
mov ch,2 ; 绿色字
mov es:[di],cx
inc si
add di,2
jmp s1
ok:
mov ax,4c00h
int 21h
code ends
end start

结果: