.model small
.stack 100h
.data
hr dw ?
min dw ?
sec dw ?
am_time db " AM$";
pm_time db " PM$";
time_is db "Your System Current time is $" ;
.code
main:
mov ax,@data
mov ds,ax
mov es,ax ; Put it in ES For valid string to be displayed
call PrintColorString
mov ah,2ch ;2ch returns time hours in ch,minutes in cl,sec in dh
int 21h
store_hours:
mov ax,0
mov al,ch
mov hr,ax
store_minutes:
mov ax,0
mov al,cl
mov min,ax
store_seconds:
mov ax,0
mov al,dh
mov sec,ax
Calculate_hrs:
mov ax,0
mov cx,0
mov ax,hr
cmp ax,11
jg pm_1digit
rest_time:
cmp al,0
jg am_2digit
mov dl,al
add dl,12
mov dh,0
mov ax,dx
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
jmp calc_mins
am_2digit:
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
calc_mins:
mov ax,min
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
calc_secs:
mov ax,sec
call two_digits_handle
cmp hr,12
jnl pmdisp
lea dx,am_time
mov ah,9h
int 21h
jmp end_lbl
pmdisp:
lea dx,pm_time
mov ah,9h
int 21h
jmp end_lbl
pm_1digit:
sub ax,12
cmp ax,0
jg pm_2digit
mov dl,al
add dl,12
mov dh,0
mov ax,dx
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
jmp calc_mins
pm_2digit:
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
jmp calc_mins
;;;;;;;;;;;;;;;;;;;;;;;;;
two_digits_handle proc
mov dl,10
div dl
mov bl,ah
mov dl,al
add dl,30h
mov ah,2h
int 21h
mov dl,bl
add dl,30h
mov ah,2h
int 21h
ret
two_digits_handle endp
;;;;;;;;;;;;;;;;;;;;;;;;;
PrintColorString proc ; Print a String in Color at ROW,COLUMN on Screen
mov ah,13h ; setup for function 13H of INT 10h API
mov al, 1 ; Color Attr in BL
mov bh, 0 ; Page 0
mov bl, 00000010 ; Color
mov cx, 28 ; Length of String
mov dh, 10 ; Row
mov dl, 20 ; Column
mov bp, OFFSET time_is ;Pointer to text
INT 10h ; Execute INT 10H API
RET
PrintColorString ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;
end_lbl:
mov ah,4ch
int 21h
end main
.stack 100h
.data
hr dw ?
min dw ?
sec dw ?
am_time db " AM$";
pm_time db " PM$";
time_is db "Your System Current time is $" ;
.code
main:
mov ax,@data
mov ds,ax
mov es,ax ; Put it in ES For valid string to be displayed
call PrintColorString
mov ah,2ch ;2ch returns time hours in ch,minutes in cl,sec in dh
int 21h
store_hours:
mov ax,0
mov al,ch
mov hr,ax
store_minutes:
mov ax,0
mov al,cl
mov min,ax
store_seconds:
mov ax,0
mov al,dh
mov sec,ax
Calculate_hrs:
mov ax,0
mov cx,0
mov ax,hr
cmp ax,11
jg pm_1digit
rest_time:
cmp al,0
jg am_2digit
mov dl,al
add dl,12
mov dh,0
mov ax,dx
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
jmp calc_mins
am_2digit:
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
calc_mins:
mov ax,min
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
calc_secs:
mov ax,sec
call two_digits_handle
cmp hr,12
jnl pmdisp
lea dx,am_time
mov ah,9h
int 21h
jmp end_lbl
pmdisp:
lea dx,pm_time
mov ah,9h
int 21h
jmp end_lbl
pm_1digit:
sub ax,12
cmp ax,0
jg pm_2digit
mov dl,al
add dl,12
mov dh,0
mov ax,dx
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
jmp calc_mins
pm_2digit:
call two_digits_handle
mov dl,':'
mov ah,2h
int 21h
jmp calc_mins
;;;;;;;;;;;;;;;;;;;;;;;;;
two_digits_handle proc
mov dl,10
div dl
mov bl,ah
mov dl,al
add dl,30h
mov ah,2h
int 21h
mov dl,bl
add dl,30h
mov ah,2h
int 21h
ret
two_digits_handle endp
;;;;;;;;;;;;;;;;;;;;;;;;;
PrintColorString proc ; Print a String in Color at ROW,COLUMN on Screen
mov ah,13h ; setup for function 13H of INT 10h API
mov al, 1 ; Color Attr in BL
mov bh, 0 ; Page 0
mov bl, 00000010 ; Color
mov cx, 28 ; Length of String
mov dh, 10 ; Row
mov dl, 20 ; Column
mov bp, OFFSET time_is ;Pointer to text
INT 10h ; Execute INT 10H API
RET
PrintColorString ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;
end_lbl:
mov ah,4ch
int 21h
end main