Get and set date and time (RTC) in DOS with assembly? -
need , set datetime (rtc) using assembly. read set date , time need use int 1ah
(func 05h
). wrote program change time , date. seems have done right, time not change:
here code:
;program (and set) current time , date (int 1ah) .model tiny .code org 100h ; СОМ-program start: call show_time ; display curr time mov ah,9 lea dx,promt ; show prompt enter new time int 21h lea si,hour ; read hours call input ; cmp cl,0ffh ; if error jz endtime ; stop enter time mov dl,':' ; add ":" after hours mov ah,2 int 21h lea si,min ; read mins call input mov ch,[hour] cmp ch,23h ; if hours not more 23 jg errortime ; if more - display error mov cl,[min] ; if mins not more 59 cmp cl,59h jg errortime ; if more - display error mov ah,03 int 1ah ; setup new time call show_time ; display curr time endtime: ;--date operations call show_date ; display curr date mov ah,9 lea dx,promt2 ; show prompt enter new date int 21h lea si,day ; read date call input cmp cl,0ffh ; if error jz enddate ; close program mov dl,'.' ; add "." separator mov ah,2 int 21h lea si,month ; read month call input cmp cl,0ffh ; if error jz enddate ; close program mov dl,'.' ; add "." separator mov ah,2 int 21h lea si,century ; read century call input cmp cl,0ffh ; if error - close program jz enddate lea si,year ; read year, without separator call input mov dh,[month] cmp dh,12h ; if month more 12 jg errortime ; close program mov dl,[day] cmp dl,31h ; if days more 31 jg errortime ; close program mov ch,[century] ; load century in ch mov cl,[year] ; load year in cl mov ah,5 int 1ah ; setup new date call show_date ; display new date enddate: ret errortime: ; if time/date entered incorect show error msg lea dx,ertime mov ah,9 int 21h ret ; , close program ;---input proc. entered number stored in [si] (in bcd format). input: mov cx,2 ; enter 2 symbols mov bx,0 ; number created in bx inhour: mov ah,01h int 21h ; 1 symbol cmp al,':' ; if ":" jz endhour cmp al,'.' ; or "." jz endhour cmp al,2fh ; if pressed enter, backspace etc. jl endinput cmp al,3ah ; if entered not number jg endinput ; xor ah,ah ; if good, clear ah sub al,30h ; convert symbol num xchg bx,ax ; ax = bx, bx = ax mov dl,10h mul dl ; add bl,al ; mov [si],bl ; save bcd number in [si] loop inhour ; endhour: ret ; close program endinput: mov cl,0ffh ; if error while input ret ; close program ;---display curr time (got cmos) show_time: mov ah,2 int 1ah ; curr time cmos xor ah,ah mov bl,10h mov al,ch mov [hour],ch ; div bl ; div 10h add ax,'00' ; mov word ptr [hourp],ax ; xor ah,ah ; mov al,cl mov [min],cl ; div bl ; div 10h add ax,'00' ; mov word ptr [minp],ax ; xor ah,ah mov al,dh div bl ; div 10h add ax,'00' ; mov word ptr [secp],ax mov ah,9 lea dx,msg ; show curr time msg int 21h ret ;---display curr date (04 func, int 1ah) show_date: mov ah,04 int 1ah ; curr date , further decompose components (day, month etc) xor ah,ah mov bl,10h mov al,ch mov [century],ch ; div bl ; div 10h add ax,'00' ; mov word ptr [centuryp],ax ; xor ah,ah mov al,cl mov [year],cl div bl ; div 10h add ax,'00' ; mov word ptr [yearp],ax xor ah,ah mov al,dl mov [day],dl div bl ; div 10h add ax,'00' ; mov word ptr [dayp],ax xor ah,ah mov al,dh mov [month],dh div bl ; div 10h add ax,'00' mov word ptr [monthp],ax mov ah,9 lea dx,msg2 ; display curr date msg int 21h ret .data msg db 0dh,0ah,'now time '; \ hourp db '00:'; curr time msg minp db '00:'; / secp db '00',0dh,0ah,'$' promt db 'please enter new time in format hh:mm',0dh,0ah,'$' ; enter new time msg promt2 db 'please enter new date in format dd.mm.yyyy',0dh,0ah,'$' ; enter new date msg ertime db 0dh,0ah,'error in format time or date$' ; error msg msg2 db 0dh,0ah,'now date '; \ dayp db '00.'; monthp db '00.'; curr date msg centuryp db '00'; yearp db '00',0dh,0ah,'$'; / hour db ? ; vars store hours, mins, century, year, month, day min db ? century db ? year db ? month db ? day db ? end start
i think, found information why system time doesn't change:
setting real-time clock date not affect system date. because real-time clock read once upon system startup, updating system timer. other references date use system timer. if either real-time clock date changed (via service) or system timer changed (via service 01h), other date not changed accordingly.
even though system uses system timer date information, both real-time clock , system timer updated continuously.
Comments
Post a Comment