; PROGRAM: GET AND SET TIME
print macro s
mov dx, offset s
mov ah, 09h
int 21h
endm
read macro num
mov ah, 01h
int 21h
mov bh, al
int 21h
mov bl, al
sub bh, 30h
mov al, 0ah
mul bh
sub bl, 30h
add al, bl
mov num, al
endm
data segment
nl db 0dh,0ah,'$'
menu db 'Time Operations:',0dh,0ah,
'1.Get Time 2.Set Time 3.Quit$'
choice db 'Choice: $'
timeis db 'Time: $'
colon db ':$'
msg_h db 'Hours: $'
msg_m db 'Minutes: $'
msg_s db 'Seconds: $'
hour db 00h
min db 00h
sec db 00h
phour db 5 dup('$')
pmin db 5 dup('$')
psec db 5 dup('$')
invOp db 'Invalid Option!$'
msg_ok db 0dh,0ah,'Time operation Successfull!$'
data ends
code segment
assume ds:data, cs:code
start:
mov ax, data
mov ds, ax
mov es, ax
print menu
ENTERCHOICE:
print nl
print choice
mov ah, 01h
int 21h
sub al, 30h
cmp al, 01h
je GETTIME
cmp al, 02h
je SETTIME
cmp al, 03h
je FINISH
print nl
print invOp
jmp ENTERCHOICE
SETTIME:
print nl
print msg_h
read hour
print nl
print msg_m
read min
print nl
print msg_s
read sec
mov ch, hour
mov cl, min
mov dh, sec
mov dl, 00h
mov ah, 2dh
int 21h
GETTIME:
print nl
mov ah, 2ch ;Interrupt to get time
int 21h
mov hour, ch
mov min, cl
mov sec, dh
mov al, hour
mov ah, 00h
mov si, offset phour
call hex2ascii
mov ah, 00h
mov al, min
mov si, offset pmin
call hex2ascii
mov ah, 00h
mov al, sec
mov si, offset psec
call hex2ascii
print timeis
print nl
print phour
print colon
print pmin
print colon
print psec
jmp ENTERCHOICE
FINISH:
mov ah, 4ch
int 21h
hex2ascii proc near
mov bx, 000ah
mov cx, 0000h
REP_DIV:
mov dx, 0000h
div bx
add dl, 30h
push dx
inc cx
cmp al, 0ah
jge REP_DIV
cmp al, 00h
je SKIP_0
add al, 30h
mov [si], al
inc si
SKIP_0:
SAVE_ASCII:
pop dx
mov [si], dl
inc si
loop SAVE_ASCII
mov [si], '$'
ret
hex2ascii endp
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>set_get_time
Time Operations:
1.Get Time 2.Set Time 3.Quit
Choice: 1
Time:
14:14:18
Choice: 2
Hours: 11
Minutes: 11
Seconds: 11
Time:
11:11:10
Choice: 1
Time:
11:11:15
Choice: 3
**************************
0 comments:
Post a Comment