Add a lap counter
This commit is contained in:
parent
5fda46d4e9
commit
5091c3a0d5
1 changed files with 56 additions and 9 deletions
65
wtfstopw.asm
65
wtfstopw.asm
|
@ -87,9 +87,13 @@ section .data
|
||||||
nl: db 0x0A
|
nl: db 0x0A
|
||||||
buf: db 0
|
buf: db 0
|
||||||
|
|
||||||
lapsmsg: db 0x0d, "New lap : "
|
lapsmsg: db 0x0d, "Lap : "
|
||||||
lapsmsglen: equ $ - lapsmsg
|
lapsmsglen: equ $ - lapsmsg
|
||||||
|
|
||||||
|
lapcount: db "00000000"
|
||||||
|
lapcountlen: equ $ - lapcount
|
||||||
|
laplen: dq 2
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
global _start
|
global _start
|
||||||
_start:
|
_start:
|
||||||
|
@ -108,8 +112,10 @@ syscall
|
||||||
cmp rax, 0
|
cmp rax, 0
|
||||||
jne fault
|
jne fault
|
||||||
|
|
||||||
|
; initializing lapptr
|
||||||
|
|
||||||
; preparing SIGINT catch
|
; preparing SIGINT catch
|
||||||
mov rax, lap_handler
|
mov rax, proc_lap_handler
|
||||||
mov qword [sigaction.sa_handler], rax
|
mov qword [sigaction.sa_handler], rax
|
||||||
mov eax, 0x10000000 ; SA_RESTART
|
mov eax, 0x10000000 ; SA_RESTART
|
||||||
or eax, 0x04000000 ; SA_RESTORER
|
or eax, 0x04000000 ; SA_RESTORER
|
||||||
|
@ -134,7 +140,7 @@ syscall
|
||||||
main_loop:
|
main_loop:
|
||||||
push 2 ; stderr
|
push 2 ; stderr
|
||||||
push 0x0D ; \r
|
push 0x0D ; \r
|
||||||
call print_time
|
call proc_print_time
|
||||||
|
|
||||||
; Attempt to read from stdin
|
; Attempt to read from stdin
|
||||||
; if something read, enter has been pressed
|
; if something read, enter has been pressed
|
||||||
|
@ -193,7 +199,7 @@ newline_exit:
|
||||||
;
|
;
|
||||||
; Print current time on FD r10 and put r13b as leading char
|
; Print current time on FD r10 and put r13b as leading char
|
||||||
;
|
;
|
||||||
print_time:
|
proc_print_time:
|
||||||
pop r8
|
pop r8
|
||||||
pop r9
|
pop r9
|
||||||
pop r10
|
pop r10
|
||||||
|
@ -317,19 +323,60 @@ print_time:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;
|
||||||
lap_handler:
|
; sig handler for SIGINT displaying lap count and time on stdout
|
||||||
|
;
|
||||||
|
proc_lap_handler:
|
||||||
mov rax, 1
|
mov rax, 1
|
||||||
mov rdi, 1
|
mov rdi, 1
|
||||||
mov rsi, lapsmsg
|
mov rsi, lapsmsg
|
||||||
mov rdx, lapsmsglen
|
mov rdx, 5 ; "Lap "
|
||||||
|
syscall
|
||||||
|
|
||||||
|
; increment the lapcount str directly
|
||||||
|
mov rbx, lapcount ; first digit ptr
|
||||||
|
add rbx, lapcountlen ; rightmost digit ptr
|
||||||
|
sub rbx, 1
|
||||||
|
mov r8, 1 ; counter
|
||||||
|
lap_handler_inc_lap:
|
||||||
|
mov r10b, [rbx]
|
||||||
|
cmp r10b, 0x39 ; '9'
|
||||||
|
jl lap_handler_inc_end
|
||||||
|
|
||||||
|
add r8, 1
|
||||||
|
cmp r8, [laplen]
|
||||||
|
jl lap_handler_laplen_noupd
|
||||||
|
mov [laplen], r8 ; update laplen
|
||||||
|
|
||||||
|
lap_handler_laplen_noupd:
|
||||||
|
mov byte [rbx], 0x30 ; set current digit to '0'
|
||||||
|
sub rbx, 1
|
||||||
|
cmp rbx, lapcount
|
||||||
|
jl fault
|
||||||
|
jmp lap_handler_inc_lap
|
||||||
|
lap_handler_inc_end:
|
||||||
|
add r10b, 1
|
||||||
|
mov [rbx], r10b
|
||||||
|
|
||||||
|
|
||||||
|
mov rax, 1
|
||||||
|
mov rdi, 1
|
||||||
|
mov rdx, [laplen]
|
||||||
|
mov rsi, lapcount
|
||||||
|
add rsi, lapcountlen
|
||||||
|
sub rsi, rdx ; leftmost digit ptr
|
||||||
|
syscall
|
||||||
|
|
||||||
|
mov rax, 1
|
||||||
|
mov rdi, 1
|
||||||
|
mov rsi, lapsmsg + 4
|
||||||
|
mov rdx, 3 ; " : "
|
||||||
syscall
|
syscall
|
||||||
|
|
||||||
push 1 ; stdout
|
push 1 ; stdout
|
||||||
push 0x0A ; \n
|
push 0x0A ; \n
|
||||||
call print_time
|
call proc_print_time
|
||||||
|
|
||||||
dbg2:
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
sig_restorer:
|
sig_restorer:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue