|
@@ -26,30 +26,125 @@ syscall
|
26
|
26
|
|
27
|
27
|
print_time:
|
28
|
28
|
|
|
29
|
+; updating ts_cur time
|
29
|
30
|
mov rax, 228 ; clock_gettime
|
30
|
31
|
mov rdi, 0 ; CLOCK_REALTIME
|
31
|
32
|
mov rsi, ts_cur
|
32
|
33
|
syscall
|
33
|
34
|
|
|
35
|
+mov rax, [tv_cur_us]
|
|
36
|
+mov rbx, [tv_start_us]
|
|
37
|
+sub rax, rbx
|
|
38
|
+cmp rax, 0
|
|
39
|
+jge print_time_us_cont
|
|
40
|
+; negativ result
|
|
41
|
+add rax, 1000000000
|
|
42
|
+mov rbx, [tv_cur_s]
|
|
43
|
+sub rbx, 1
|
|
44
|
+mov [tv_cur_s], rbx
|
|
45
|
+print_time_us_cont:
|
|
46
|
+xor rdx, rdx
|
|
47
|
+mov rcx, 100000
|
|
48
|
+div rcx
|
|
49
|
+; set the us char in timestr
|
|
50
|
+mov r8, timestr
|
|
51
|
+add r8, 10 ; r8 points on last char before \r
|
|
52
|
+mov r9, 4 ; r9 count the number of digits
|
|
53
|
+print_time_us_loop:
|
|
54
|
+ xor rdx, rdx
|
|
55
|
+ mov rcx, 10
|
|
56
|
+ div rcx
|
|
57
|
+ add dl, 0x30
|
|
58
|
+ mov [r8], dl
|
|
59
|
+ sub r8, 1
|
|
60
|
+ sub r9, 1
|
|
61
|
+ cmp r9, 0
|
|
62
|
+ jg print_time_us_loop
|
|
63
|
+
|
|
64
|
+; handling seconds, minutes & hours
|
34
|
65
|
mov rax, [tv_cur_s]
|
35
|
66
|
mov rbx, [tv_start_s]
|
36
|
67
|
sub rax, rbx
|
37
|
|
-fifoo:
|
|
68
|
+; rax now contain elapsed seconds
|
|
69
|
+; filling timestr with seconds & minutes
|
|
70
|
+add rax, 3559
|
|
71
|
+
|
|
72
|
+xor rdx, rdx
|
|
73
|
+mov rcx, 10
|
|
74
|
+div rcx
|
|
75
|
+push rax
|
|
76
|
+mov rax, rdx
|
|
77
|
+add al, 0x30
|
|
78
|
+mov byte [timestr + 5], al
|
|
79
|
+
|
|
80
|
+pop rax
|
|
81
|
+xor rdx, rdx
|
|
82
|
+mov rcx, 6
|
|
83
|
+div rcx
|
|
84
|
+push rax
|
|
85
|
+mov rax, rdx
|
|
86
|
+add al, 0x30
|
|
87
|
+mov byte [timestr + 4], al
|
|
88
|
+
|
|
89
|
+pop rax
|
|
90
|
+xor rdx, rdx
|
|
91
|
+mov rcx, 10
|
|
92
|
+div rcx
|
|
93
|
+push rax
|
|
94
|
+mov rax, rdx
|
38
|
95
|
add al, 0x30
|
39
|
|
-mov byte [msg], al
|
40
|
|
-;xor rax, rax
|
41
|
|
-;mov al, byte [msg]
|
42
|
|
-;mov rdi, [tv_cur_s]
|
43
|
|
-;mov rdx, [tv_start_s]
|
44
|
|
-;sub rdi, rdx
|
45
|
|
-;fifoo:
|
46
|
|
-;add rax, rdi
|
47
|
|
-;mov byte [msg], al
|
48
|
|
-
|
49
|
|
-mov rax, 1
|
50
|
|
-mov rdi, 1
|
51
|
|
-mov rsi, msg
|
52
|
|
-mov rdx, msglen
|
|
96
|
+mov byte [timestr + 2], al
|
|
97
|
+
|
|
98
|
+pop rax
|
|
99
|
+xor rdx, rdx
|
|
100
|
+mov rcx, 6
|
|
101
|
+div rcx
|
|
102
|
+push rax
|
|
103
|
+mov rax, rdx
|
|
104
|
+add al, 0x30
|
|
105
|
+mov byte[timestr + 1], al
|
|
106
|
+
|
|
107
|
+; filling the hours buffer
|
|
108
|
+; r8 will contain our digits counter : max is 8
|
|
109
|
+mov r8, 8
|
|
110
|
+pop rax
|
|
111
|
+print_time_hours_loop:
|
|
112
|
+ mov rcx, 10
|
|
113
|
+ xor rdx, rdx
|
|
114
|
+ div rcx
|
|
115
|
+ add dl, 0x30
|
|
116
|
+ cmp rax, 0
|
|
117
|
+ jne print_time_hours_print_mod
|
|
118
|
+ cmp rdx, 0
|
|
119
|
+ je print_time_hours_loop_end
|
|
120
|
+
|
|
121
|
+ print_time_hours_print_mod:
|
|
122
|
+ mov r9, hours
|
|
123
|
+ add r9, r8
|
|
124
|
+ mov byte [r9], dl
|
|
125
|
+ cmp r8, 0
|
|
126
|
+ je fault
|
|
127
|
+ sub r8, 1
|
|
128
|
+ cmp rax, 0
|
|
129
|
+ jne print_time_hours_loop
|
|
130
|
+print_time_hours_loop_end:
|
|
131
|
+
|
|
132
|
+; print hours + timestr
|
|
133
|
+add r8, 1
|
|
134
|
+cmp r8, 7
|
|
135
|
+jle print_time_hours_cont
|
|
136
|
+mov r8, 7
|
|
137
|
+print_time_hours_cont:
|
|
138
|
+mov r9, hours
|
|
139
|
+add r9, r8
|
|
140
|
+mov rcx, 9
|
|
141
|
+sub rcx, r8
|
|
142
|
+add rcx, timestrlen
|
|
143
|
+
|
|
144
|
+mov rax, 1 ; write
|
|
145
|
+mov rdi, 1 ; stdout
|
|
146
|
+mov rsi, r9
|
|
147
|
+mov rdx, rcx
|
53
|
148
|
syscall
|
54
|
149
|
|
55
|
150
|
sleep:
|
|
@@ -59,9 +154,15 @@ mov rsi, 0
|
59
|
154
|
syscall
|
60
|
155
|
jmp print_time
|
61
|
156
|
|
62
|
|
-mov rax, 60 ; sys_exit
|
63
|
|
-mov rdi, 0 ; 0
|
64
|
|
-syscall
|
|
157
|
+exit:
|
|
158
|
+ mov rax, 60 ; sys_exit
|
|
159
|
+ mov rdi, 0 ; OK
|
|
160
|
+ syscall
|
|
161
|
+fault:
|
|
162
|
+ mov rax, 60 ; sys_exit
|
|
163
|
+ mov rdi, 1 ; failure
|
|
164
|
+ syscall
|
|
165
|
+
|
65
|
166
|
|
66
|
167
|
dumprax:
|
67
|
168
|
push rax
|
|
@@ -113,6 +214,10 @@ ts_start:
|
113
|
214
|
msg: db "0 Hello, world!", 10
|
114
|
215
|
msglen: equ $ - msg
|
115
|
216
|
|
|
217
|
+hours: db "000000000"
|
|
218
|
+timestr: db ":00:00.0000", 0x0D
|
|
219
|
+timestrlen: equ $ - timestr
|
|
220
|
+
|
116
|
221
|
digit: db "0"
|
117
|
222
|
nl: db 10
|
118
|
223
|
|
|
@@ -120,15 +225,15 @@ ts_cur:
|
120
|
225
|
tv_cur_s dq 0
|
121
|
226
|
tv_cur_us dq 0
|
122
|
227
|
|
123
|
|
-;ts_sleep:
|
124
|
|
-; tv_sleep_s dd 0,0
|
125
|
|
-; tv_sleep_us dd 10000000,0
|
|
228
|
+ts_sleep:
|
|
229
|
+ tv_sleep_s dd 0,0
|
|
230
|
+ tv_sleep_us dd 10000000,0
|
126
|
231
|
|
127
|
232
|
|
128
|
|
-; 1/2s sleep
|
129
|
|
-ts_sleep:
|
130
|
|
- tv_sleep_s dq 0
|
131
|
|
- tv_sleep_us dq 500000000
|
|
233
|
+;; 1/2s sleep
|
|
234
|
+;ts_sleep:
|
|
235
|
+; tv_sleep_s dq 0
|
|
236
|
+; tv_sleep_us dq 500000000
|
132
|
237
|
|
133
|
238
|
|
134
|
239
|
.end:
|