|
@@ -87,9 +87,13 @@ section .data
|
87
|
87
|
nl: db 0x0A
|
88
|
88
|
buf: db 0
|
89
|
89
|
|
90
|
|
- lapsmsg: db 0x0d, "New lap : "
|
|
90
|
+ lapsmsg: db 0x0d, "Lap : "
|
91
|
91
|
lapsmsglen: equ $ - lapsmsg
|
92
|
92
|
|
|
93
|
+ lapcount: db "00000000"
|
|
94
|
+ lapcountlen: equ $ - lapcount
|
|
95
|
+ laplen: dq 2
|
|
96
|
+
|
93
|
97
|
section .text
|
94
|
98
|
global _start
|
95
|
99
|
_start:
|
|
@@ -108,8 +112,10 @@ syscall
|
108
|
112
|
cmp rax, 0
|
109
|
113
|
jne fault
|
110
|
114
|
|
|
115
|
+; initializing lapptr
|
|
116
|
+
|
111
|
117
|
; preparing SIGINT catch
|
112
|
|
-mov rax, lap_handler
|
|
118
|
+mov rax, proc_lap_handler
|
113
|
119
|
mov qword [sigaction.sa_handler], rax
|
114
|
120
|
mov eax, 0x10000000 ; SA_RESTART
|
115
|
121
|
or eax, 0x04000000 ; SA_RESTORER
|
|
@@ -134,7 +140,7 @@ syscall
|
134
|
140
|
main_loop:
|
135
|
141
|
push 2 ; stderr
|
136
|
142
|
push 0x0D ; \r
|
137
|
|
- call print_time
|
|
143
|
+ call proc_print_time
|
138
|
144
|
|
139
|
145
|
; Attempt to read from stdin
|
140
|
146
|
; if something read, enter has been pressed
|
|
@@ -193,7 +199,7 @@ newline_exit:
|
193
|
199
|
;
|
194
|
200
|
; Print current time on FD r10 and put r13b as leading char
|
195
|
201
|
;
|
196
|
|
-print_time:
|
|
202
|
+proc_print_time:
|
197
|
203
|
pop r8
|
198
|
204
|
pop r9
|
199
|
205
|
pop r10
|
|
@@ -317,19 +323,60 @@ print_time:
|
317
|
323
|
|
318
|
324
|
ret
|
319
|
325
|
|
320
|
|
-
|
321
|
|
-lap_handler:
|
|
326
|
+;
|
|
327
|
+; sig handler for SIGINT displaying lap count and time on stdout
|
|
328
|
+;
|
|
329
|
+proc_lap_handler:
|
322
|
330
|
mov rax, 1
|
323
|
331
|
mov rdi, 1
|
324
|
332
|
mov rsi, lapsmsg
|
325
|
|
- mov rdx, lapsmsglen
|
|
333
|
+ mov rdx, 5 ; "Lap "
|
|
334
|
+ syscall
|
|
335
|
+
|
|
336
|
+ ; increment the lapcount str directly
|
|
337
|
+ mov rbx, lapcount ; first digit ptr
|
|
338
|
+ add rbx, lapcountlen ; rightmost digit ptr
|
|
339
|
+ sub rbx, 1
|
|
340
|
+ mov r8, 1 ; counter
|
|
341
|
+ lap_handler_inc_lap:
|
|
342
|
+ mov r10b, [rbx]
|
|
343
|
+ cmp r10b, 0x39 ; '9'
|
|
344
|
+ jl lap_handler_inc_end
|
|
345
|
+
|
|
346
|
+ add r8, 1
|
|
347
|
+ cmp r8, [laplen]
|
|
348
|
+ jl lap_handler_laplen_noupd
|
|
349
|
+ mov [laplen], r8 ; update laplen
|
|
350
|
+
|
|
351
|
+ lap_handler_laplen_noupd:
|
|
352
|
+ mov byte [rbx], 0x30 ; set current digit to '0'
|
|
353
|
+ sub rbx, 1
|
|
354
|
+ cmp rbx, lapcount
|
|
355
|
+ jl fault
|
|
356
|
+ jmp lap_handler_inc_lap
|
|
357
|
+ lap_handler_inc_end:
|
|
358
|
+ add r10b, 1
|
|
359
|
+ mov [rbx], r10b
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+ mov rax, 1
|
|
363
|
+ mov rdi, 1
|
|
364
|
+ mov rdx, [laplen]
|
|
365
|
+ mov rsi, lapcount
|
|
366
|
+ add rsi, lapcountlen
|
|
367
|
+ sub rsi, rdx ; leftmost digit ptr
|
|
368
|
+ syscall
|
|
369
|
+
|
|
370
|
+ mov rax, 1
|
|
371
|
+ mov rdi, 1
|
|
372
|
+ mov rsi, lapsmsg + 4
|
|
373
|
+ mov rdx, 3 ; " : "
|
326
|
374
|
syscall
|
327
|
375
|
|
328
|
376
|
push 1 ; stdout
|
329
|
377
|
push 0x0A ; \n
|
330
|
|
- call print_time
|
|
378
|
+ call proc_print_time
|
331
|
379
|
|
332
|
|
-dbg2:
|
333
|
380
|
ret
|
334
|
381
|
|
335
|
382
|
sig_restorer:
|