Sunteți pe pagina 1din 6

is my code:

;program get (and set) current time and date (int 1ah)
.model tiny
.code

org 100h ; СОМ-program


start:

call show_time ; display curr time


mov ah,9
lea dx,promt ; show prompt to enter the 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 than 23
jg errortime ; if more - display error
mov cl,[min] ; if mins not more than 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 to enter the new date
int 21h
lea si,day ; read date
call input
cmp cl,0ffh ; if error
jz enddate ; close program
mov dl,'.' ; add "." as 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 "." as 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 than 12
jg errortime ; close program
mov dl,[day]
cmp dl,31h ; if days more than 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 the new date
enddate:
ret

errortime: ; if time/date was entered incorect then show error msg


lea dx,ertime
mov ah,9
int 21h
ret ; and close program

;---input proc. Entered number stored in [si] (in BCD format).


input:
mov cx,2 ; enter 2 symbols
mov bx,0 ; number will be created in bx
inhour:
mov ah,01h
int 21h ; get 1 symbol
cmp al,':' ; if ":"
jz endhour
cmp al,'.' ; or "."
jz endhour
cmp al,2fH ; if was pressed enter, backspace etc.
jl endinput
cmp al,3AH ; if was entered not number
jg endinput ;
xor ah,ah ; if all good, then clear ah
sub al,30h ; convert symbol to 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 from CMOS)
show_time:
mov ah,2
int 1ah ; get curr time from CMOS
xor ah,ah
mov bl,10h
mov al,ch
mov [hour],ch ;
div bl ; div by 10h
add ax,'00' ;
mov word ptr [hourp],ax ;
xor ah,ah ;
mov al,cl
mov [min],cl ;
div bl ; div by 10h
add ax,'00' ;
mov word ptr [minp],ax ;
xor ah,ah
mov al,dh
div bl ; div by 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 ; get curr date and further decompose it into components (day,
month etc)
xor ah,ah
mov bl,10h
mov al,ch
mov [century],ch ;
div bl ; div by 10h
add ax,'00' ;
mov word ptr [centuryp],ax ;
xor ah,ah
mov al,cl
mov [year],cl
div bl ; div by 10h
add ax,'00' ;
mov word ptr [yearp],ax
xor ah,ah
mov al,dl
mov [day],dl
div bl ; div by 10h
add ax,'00' ;
mov word ptr [dayp],ax
xor ah,ah
mov al,dh
mov [month],dh
div bl ; div by 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 is '; \
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 is '; \
dayp db '00.';
monthp db '00.'; curr date msg
centuryp db '00';
yearp db '00',0dh,0ah,'$'; /
hour db ? ; vars to store hours, mins, century, year, month, day
min db ?
century db ?
year db ?
month db ?
day db ?

end start
share improve this question

askedSep 21 '14 at 11:57

dedoki
341●3●11●22

editedSep 25 '15 at 9:47

Ciro Santilli 刘晓波死 六四事件 法轮功


95.1k●18●381●319
Related: stackoverflow.com/questions/1465927/… – Ciro
Santilli 刘晓波死 六四事件 法轮功 Sep 25 '15 at 9:49

add a comment

1 Answer

order by active oldest votes

up vote0down voteaccepted

I think, I found information why system time doesn't change:

Setting the real-time clock date will not affect the system date. This is because the real-time
clock is read once upon system startup, updating the system timer. All other references to date
use the system timer. If either the real-time clock date is changed (via this service) or the
system timer is changed (via Service 01h), the other date is not changed accordingly.
Even though the system uses the system timer for date information, both the real-time clock
and the system timer are updated continuously.

http://www.cs.ubbcluj.ro/~dadi/ac/doc/ng8f85f.html
share improve this answer

answeredSep 21 '14 at 18:47

dedoki
341●3●11●22

Your Answer
Body

 Add picture

Log in

OR

Name

Email

By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app

S-ar putea să vă placă și