-
Notifications
You must be signed in to change notification settings - Fork 0
/
date and time functions.asm
119 lines (88 loc) · 2.42 KB
/
date and time functions.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
; Date and time functions
; Get date and time and save to file using Disk Operating System interrupts.
; The program prints the date and saves it to file when running from emu8086 the path is:
; c:\emu8086\vdrive\c\date.txt
; when running from dos prompt the path is:
; c:\date.txt
name "datefile"
org 100h
TAB EQU 9 ; ASCII CODE
mov ah, 2ah ; get date
int 21h
lea bx, week_table
xlat
mov w. week, al ; 0=sunday
add cx, 0f830h ; for years
mov ax, cx
call deci
mov w. year, ax
mov al, dh ; month
call deci
mov w. mont, ax
mov al, dl ; day
call deci
mov w. day, ax
mov ah, 2ch ; get time
int 21h
mov al, ch ; hour
call deci
mov w. hour, ax
mov al, cl ; minute
call deci
mov w. minu, ax
mov al, dh ; second
call deci
mov w. seco, ax
mov ah, TAB
mov dx, offset txt
int 21h
mov cx, 0 ; file attribute
mov ax, 3c00h ; create new file
mov dx, offset fildat
int 21h
jb error ; error
mov w. handle, ax
mov ax, 4200h
mov bx, w. handle
xor cx, cx ; begin byte 0
xor dx, dx ;
int 21h
jb error
mov ah, 40h ; write to file
mov bx, w. handle
mov cx, offset seco - offset txt ; 34 bytes
mov dx, offset dat
int 21h
jb error
mov ah, 3eh ; close file.
mov bx, w. handle
int 21h
; wait for any key press:
mov ah, 0
int 16h
error: ; leave program (unconditionally).
mov ax, 4c00h
int 21h
deci: ; calculate in decimal
push cx
xor ah, ah
mov cl, 10
div cl
add ax, 3030h
pop cx
ret
fildat db "c:\date.txt",0 ; where to save date and time.
handle db 0,0
; here's data to display the date and time
txt db 0Dh, 0Ah, 0Ah, TAB, TAB ; jump line and go two tabs right
dat db "week day: "
week db 0, TAB ; put the day 1=monday 9 jump a colon (tab)
db "20"
year db 0, 0, '-'
mont db 0, 0, '-'
day db 0, 0, TAB
hour db 0, 0, ':'
minu db 0, 0, ':'
seco db 0, 0, ' '
db 0Dh, 0Ah, 24h ; line feed return and stop symbol 24h=$ (ASCII).
week_table db "SMTWTFS"