[Hb-XIV] 访问CMOS RAM(端口)

《汇编语言·第三版》--王爽


1 问题

编程,以“年/月/日 时:分:秒”的格式,显示当前的日期、时间。


注意:CMOS RAM中存储着系统的配置信息,除了保存时间信息的单元外,不要向其它的单元写入内容,否则将引起一些系统错误。


2 代码

1.        assume    cs:codesg

2.         

3.        data segment

4.                 db     13 dup(0), 0

5.        data ends

6.         

7.        codesg     segment

8.        start:

9.                 mov ax, data

10.             mov ds, ax

11.             mov si, 0

12.             mov al, 9

13.            

14.             mov cx, 3

15.             y_m_d:

16.                       call far ptr         r_CR_y

17.                       add  si, 2

18.                      mov byte ptr    ds:[si], '/'

19.                       inc    si

20.                       dec   al

21.             loop y_m_d               ;读取"年/月/日/"到ds:[si]

22.            

23.             mov cx, 3

24.             mov al, 4

25.             h_m_s:

26.                       call far ptr         r_CR_y

27.                       add  si, 2

28.                       mov byte ptr    ds:[si],':'

29.                       inc    si

30.                       sub   al, 2

31.             loop h_m_s               ;读取"时:分:秒"到ds:[si]

32.             mov byte ptr    ds:[si],0

33.            

34.             mov ax, data

35.             mov ds, ax

36.             mov si, 0

37.             mov dx, 0cfh

38.             mov cl, 2

39.             call far ptr show_str

40.            

41.             mov ax, 4c00h

42.             int    21h

43.            

44.             ;功能:读取CMOS RAM芯片内指定单元的内容,将读取到的内容保存到ds:[si]指向的内存中

45.             ;参数:(al) = 将要读取的CMOS RAM内存单元

46.             ;返回:无

47.             r_CR_y:

48.                       push          ax

49.                       push          cx

50.                       push          si

51.                      

52.                       out   70h, al

53.                       in      al,71h               ;读CMOS RAM 9号内存单元

54.                      

55.                       mov ah, al

56.                       mov cl, 4

57.                       shr   ah, cl

58.                       and  al,00001111b

59.                      

60.                       add  ah, 30h

61.                       add  al, 30h

62.                      

63.                       mov ds:[si],ah

64.                       inc    si

65.                       mov ds:[si],al

66.                      

67.                       pop  si

68.                       pop  cx

69.                       pop  ax

70.             retf

71.            

72.             ;功能:在指定的位置,用指定的颜色,显示一个用0结束的字符串

73.             ;参数:(dh) = 行号(取值范围 0 ~ 24),(dl) = 列号(取值范围0 ~ 79),(cl) = 颜色,ds:si指向字符串的首地址

74.             ;返回:无

75.             show_str:

76.                       push          ax

77.                       push          cx

78.                       push          dx

79.                       push          es

80.                       push          bp

81.                       push          di

82.                       push          si

83.                      

84.                       mov ax, 0b800h

85.                       mov es, ax        ;es段保存显存段地址

86.                      

87.                       mov al, cl ;字符前景色保存到al

88.                      

89.                       mov bp, 0

90.                       mov ch, 0

91.                       mov cl, dh

92.                       inc    cl

93.                       str_s0:

94.                                jcxz  str_s1

95.                                add  bp,160              ;行号对应的显存地址

96.                                loop str_s0

97.                       str_s1:

98.                                mov di,0

99.                                mov ch,0

100.                              mov cl, dl

101.                     str_s2:    

102.                              jcxz  str_s3

103.                              add  di, 2           ;列号对应的显存地址

104.                              loop str_s2                ;es:[di+ bp]为dh行dl列对应的显存地址

105.                             

106.                     str_s3:    

107.                              mov cl, ds:[si]

108.                              jcxz  str_s4                ;检测当前字符是否为0,如果为0则转移到s4处执行

109.                              mov        es:[bp + di],cl

110.                              inc    di

111.                              mov        es:[bp +di], al           ;字符前景色

112.                              inc    di

113.                              inc    si

114.                              loop str_s3

115.                                      

116.                     str_s4:    

117.                              pop  si

118.                              pop  di

119.                              pop  bp

120.                              pop  es

121.                              pop  dx

122.                              pop  cx

123.                              pop  ax

124.           retf

125.  codesg     ends

126.   end         start

3 调试

Figure1. 从CMOS RAM端口读取日期时间显示结果
[2014.12.20 - 20:33]
R《Hb》Note Over.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值