flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Get Date/Time using CMOS/BIOS

Author
Thread Post new topic Reply to topic
mbr_tsr



Joined: 03 Apr 2011
Posts: 12092
mbr_tsr 08 Dec 2013, 22:56
Code:

;DateTime.Asm Converted to FASM by S.T.C

;Show current date and time
;Date time store in CMOS
;70h port store addr,71h port read data
;Date time data addr:
; second:0 minute:2 hour:4 date:7 month:8 year:9
;Date time data format:BCD,4 unit binary describe a digit
;1 byte,high addr=decade

Org 100h
start:

push cs
push cs
pop ds
pop es

mov ah,03h ;No.3 sub in 10h interrupt,get cursor
int 10h;Return bh=page num,dh=line num,dl=column number
mov di,MyStore
;save bh,dh,dl
mov [es:di],bx
mov [es:di+2],dx

refresh_datetime:
;restore page\line\col number (bh,dh,dl)
mov bx,[es:di]
mov dx,[es:di+2]

;reset to old page\line\column number
mov ah,02h ;set cursor
int 10h

;read year
mov al,9
mov ah,2
mov si, MyData
call read_cmos_bcd

;read month
mov al,8
mov ah,1
inc si
call read_cmos_bcd

;read date
mov al,7
mov ah,1
inc si
call read_cmos_bcd

;read hour
mov al,4
mov ah,1
inc si
call read_cmos_bcd

;read munite
mov al,2
mov ah,1
inc si
call read_cmos_bcd

;read second
mov al,0
mov ah,1
inc si
call read_cmos_bcd

mov dx,MyData ;string start addr
mov ah,9
int 21h

mov ah, 0
int 0x16

;dead loop is not a resolution,it cause cpu turn to 100%
;jmp refresh_datetime
mov ax,4c00h
int 21h


read_cmos_bcd:
;Args:
;al => start addr
;Return:
;Write converted string in ds:si
;si point to the end of string after called
push cx

out 70h,al
in al,71h ;read one byte
mov ah,al
;For convenience
;al store byte high 4 bit
;ah store byte low 4 bit
;Because,human read order
;High bit put low addr
;Example:string "12","1" must store in low addr in memory

mov cl,4
shr al,cl ;only retain high 4 bit
and ah,00001111b ;clear high 4 bit to 0

add ah,30h
add al,30h

mov [ds:si],ax
add si,2

pop cx
ret

MyData db "00-00-00 00:00:00$"
MyStore rb 16
    
Post 08 Dec 2013, 22:56
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Dec 2013, 02:34
mbr_tsr,

hlt / jmp probably can lower CPU usage; paired mov al, x / mov ah, y usually are replaced by mov ax, y*256+x (almost the same for add).
Post 09 Dec 2013, 02:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.