|
@@ -80,14 +80,14 @@ section .data
|
80
|
80
|
SIGACTION sigaction
|
81
|
81
|
|
82
|
82
|
align 8
|
83
|
|
- hours: times 8 db '0' ; allows storing max hours in 1<<64 secs
|
|
83
|
+ hours: times 8 db '0' ; 8 digits is the max for hours
|
84
|
84
|
timestr: db ":00:00."
|
85
|
|
- times 8 db '0'
|
|
85
|
+ times 8 db '0' ; 8 digits for nanoseconds
|
86
|
86
|
times 0xE db ' '
|
87
|
87
|
db 0
|
88
|
88
|
timestrend: align 8
|
89
|
89
|
timestrlen: equ timestrend - timestr
|
90
|
|
- hourslen: equ timestr - hours ; hours len -> the max number of digits
|
|
90
|
+ %define HOURSLEN 8
|
91
|
91
|
|
92
|
92
|
lapsmsg: db "Lap : "
|
93
|
93
|
lapsmsglen: equ $ - lapsmsg
|
|
@@ -291,6 +291,9 @@ proc_print_time:
|
291
|
291
|
xor rdx, rdx
|
292
|
292
|
div qword [ts_sleep.tv_nsec] ; Divide result given time_res
|
293
|
293
|
|
|
294
|
+ mov r9, [rsp + 8]
|
|
295
|
+ mov byte [timestr+timestrlen-1], r9b ; set last chr from 1st argument
|
|
296
|
+
|
294
|
297
|
; set the nanosec chars (time_res chars) in timestr
|
295
|
298
|
mov rbx, 0x2020202020202020
|
296
|
299
|
mov rcx, [time_res]
|
|
@@ -298,7 +301,7 @@ proc_print_time:
|
298
|
301
|
procpt_loopns:
|
299
|
302
|
xor rdx, rdx
|
300
|
303
|
div r8
|
301
|
|
- add dl, '0'
|
|
304
|
+ or dl, 0x30 ; '0'
|
302
|
305
|
shl rbx, 8
|
303
|
306
|
mov bl, dl
|
304
|
307
|
loop procpt_loopns
|
|
@@ -317,7 +320,7 @@ proc_print_time:
|
317
|
320
|
xor dl, dl
|
318
|
321
|
div r9
|
319
|
322
|
mov bl, dl
|
320
|
|
- add bx, 0x3030
|
|
323
|
+ or bx, 0x3030
|
321
|
324
|
mov word [timestr + 4], bx
|
322
|
325
|
|
323
|
326
|
xor dl, dl
|
|
@@ -326,48 +329,41 @@ proc_print_time:
|
326
|
329
|
xor dl, dl
|
327
|
330
|
div r9
|
328
|
331
|
mov bl, dl
|
329
|
|
- add bx, 0x3030
|
|
332
|
+ or bx, 0x3030
|
330
|
333
|
mov word [timestr + 1], bx
|
331
|
334
|
|
332
|
|
- ; filling the hours buffer
|
333
|
|
- ; rcx will contain max_digits - digits_count
|
334
|
|
- ; digits max is hourslen - 1
|
335
|
|
- mov rcx, hourslen - 1
|
336
|
|
- mov rdi, hours + hourslen - 1
|
337
|
|
- mov r10, 10
|
338
|
|
- procpt_loop:
|
|
335
|
+ ; using rbx to stores the hours string
|
|
336
|
+ xor rbx, rbx
|
|
337
|
+ mov rcx, HOURSLEN
|
|
338
|
+ mov r8, 10
|
|
339
|
+ procpt_looph:
|
339
|
340
|
xor dl, dl
|
340
|
|
- div r10
|
341
|
|
- cmp rax, 0
|
342
|
|
- jne procpt_loopcont
|
343
|
|
- cmp dl, 0
|
344
|
|
- je procpt_loop_end
|
345
|
|
-
|
346
|
|
- procpt_loopcont:
|
347
|
|
- xchg al, dl
|
348
|
|
- add al, 0x30
|
349
|
|
- stosb
|
350
|
|
- mov al, dl
|
351
|
|
- cmp rcx, 0
|
352
|
|
- je fault
|
|
341
|
+ div r8
|
|
342
|
+ shl rbx, 8
|
|
343
|
+ mov bl, dl
|
353
|
344
|
cmp rax, 0
|
354
|
|
- loopne procpt_loop
|
355
|
|
- procpt_loop_end:
|
356
|
|
-
|
357
|
|
- ; set rcx for 2 digits at least for hours
|
358
|
|
- mov r9, hourslen - 2
|
359
|
|
- add rcx, 1
|
360
|
|
- cmp rcx, r9
|
361
|
|
- cmovnle rcx, r9
|
|
345
|
+ loopne procpt_looph
|
|
346
|
+ procpt_looph_end:
|
|
347
|
+
|
|
348
|
+ mov r8, HOURSLEN - 2
|
|
349
|
+ cmp rcx, HOURSLEN - 2
|
|
350
|
+ cmovl r8, rcx ; r8 stores hours digit count (at least 2)
|
|
351
|
+ cmp rcx, 0
|
|
352
|
+ jz procpt_looph2_end
|
|
353
|
+ procpt_looph2:
|
|
354
|
+ shl rbx, 8
|
|
355
|
+ loopne procpt_looph2
|
|
356
|
+ procpt_looph2_end:
|
362
|
357
|
|
363
|
|
- mov r10, [rsp + 8] ; leading chr as 1st argument
|
364
|
|
- mov byte [timestr+timestrlen-1], r10b
|
|
358
|
+ mov r9, 0x3030303030303030 ; ASCII convertion
|
|
359
|
+ or rbx, r9
|
|
360
|
+ mov [hours], rbx
|
365
|
361
|
|
366
|
362
|
mov rax, 1 ; write
|
367
|
363
|
mov rdi, [rsp + 16] ; fd as 2nd argument
|
368
|
|
- mov rdx, timestrlen + hourslen
|
369
|
|
- sub rdx, rcx ; timestr + hours len
|
370
|
|
- lea rsi, [hours + rcx] ; hours start pointer
|
|
364
|
+ lea rsi, [hours + r8] ; hours start pointer
|
|
365
|
+ mov rdx, timestrlen + HOURSLEN
|
|
366
|
+ sub rdx, r8 ; timestr + hours len
|
371
|
367
|
syscall
|
372
|
368
|
|
373
|
369
|
ret 16
|