Browse Source

Enhancement in file header

Moved the macro before .data section
Add a .bss section
Reorganisation of .data section
Yann Weber 6 years ago
parent
commit
862666d41e
1 changed files with 39 additions and 32 deletions
  1. 39
    32
      wtfstopw.asm

+ 39
- 32
wtfstopw.asm View File

26
 ; Interact :
26
 ; Interact :
27
 ; 	press enter to exit
27
 ; 	press enter to exit
28
 ; 	send SIGINT (with kill -2 ir ctrl + c) for a new lap
28
 ; 	send SIGINT (with kill -2 ir ctrl + c) for a new lap
29
-
30
-
31
-
32
 [bits 64]
29
 [bits 64]
33
 
30
 
31
+%define O_NONBLOCK 0x800
32
+
34
 STRUC TIMESPEC_STRUC
33
 STRUC TIMESPEC_STRUC
35
 	.tv_sec: resq 1
34
 	.tv_sec: resq 1
36
 	.tv_nsec: resq 1
35
 	.tv_nsec: resq 1
37
 ENDSTRUC
36
 ENDSTRUC
38
 
37
 
39
 
38
 
40
-%macro TIMESPEC 3
39
+%macro TIMESPEC 1
41
 	%1: ISTRUC TIMESPEC_STRUC
40
 	%1: ISTRUC TIMESPEC_STRUC
42
-		at TIMESPEC_STRUC.tv_sec, dq %2
43
-		at TIMESPEC_STRUC.tv_nsec, dq %3
41
+		at TIMESPEC_STRUC.tv_sec, resq 1
42
+		at TIMESPEC_STRUC.tv_nsec, resq 1
44
 	IEND
43
 	IEND
45
 	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
44
 	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
46
 	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
45
 	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
53
 	.sa_mask:         resb      128
52
 	.sa_mask:         resb      128
54
 ENDSTRUC
53
 ENDSTRUC
55
 
54
 
56
-section .data
57
-
58
-	sigaction: ISTRUC SIGACTION_STRUC
55
+; from https://www.linuxnasm.be/home/library/lib-includes/signals-inc
56
+%macro SIGACTION 1
57
+	%1: ISTRUC SIGACTION_STRUC
59
 		at  SIGACTION_STRUC.sa_handler, dq 0
58
 		at  SIGACTION_STRUC.sa_handler, dq 0
60
 		at  SIGACTION_STRUC.sa_flags, dq 0
59
 		at  SIGACTION_STRUC.sa_flags, dq 0
61
 		at  SIGACTION_STRUC.sa_restorer, dq 0
60
 		at  SIGACTION_STRUC.sa_restorer, dq 0
65
 	%define sigaction.sa_flags sigaction+SIGACTION_STRUC.sa_flags
64
 	%define sigaction.sa_flags sigaction+SIGACTION_STRUC.sa_flags
66
 	%define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
65
 	%define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
67
 	%define sigaction.sa_mask sigaction+SIGACTION_STRUC.sa_mask
66
 	%define sigaction.sa_mask sigaction+SIGACTION_STRUC.sa_mask
67
+%endmacro
68
 
68
 
69
-	TIMESPEC ts_start, 0, 0
70
-	TIMESPEC ts_cur, 0, 0
71
-	TIMESPEC ts_sleep, 0, 100000000 ; set before mainloop
69
+section .bss
70
+align 8
71
+	TIMESPEC ts_start
72
+	TIMESPEC ts_cur
73
+	TIMESPEC ts_sleep
74
+	buf: resb 1
72
 
75
 
76
+section .data
73
 
77
 
74
-	faultmsg: db "Fault !", 0xA
75
-	faultmsglen: equ $ - faultmsg
78
+	time_res: dq 2 ; 2 digits bellow seconds can grow to 8
79
+	fcntl_flag: dq 0
80
+	SIGACTION sigaction
81
+
82
+	align 8
83
+	hours: times 8 db '0' ; allows storing max hours in 1<<64 secs
84
+	timestr: db ":00:00.0           ", 0
85
+	align 8
86
+	timestrlen: equ $ - timestr
87
+	hourslen: equ timestr - hours ; hours len -> the max number of digits
88
+
89
+	lapsmsg: db "Lap : "
90
+	lapsmsglen: equ $ - lapsmsg
91
+
92
+	lapcount: times 20 db '0' ; allows storing decimal repr of 1<<64
93
+	lapcountlen: equ $ - lapcount
94
+	laplen: dq 2
76
 
95
 
77
 	startmsg: db "Press Enter or ctrl+d to exit and ctrl+c for new lap."
96
 	startmsg: db "Press Enter or ctrl+d to exit and ctrl+c for new lap."
78
 	db 0xA
97
 	db 0xA
100
 	badval_msg: db "Value for -r should be in [1..8] but got "
119
 	badval_msg: db "Value for -r should be in [1..8] but got "
101
 	badval_msglen: equ $ - badval_msg
120
 	badval_msglen: equ $ - badval_msg
102
 
121
 
103
-	hours: db "000000000" ; increase size of this string to increase hours max
104
-	timestr: db ":00:00.0           ", 0
105
-	timestrlen: equ $ - timestr
106
-	hourslen: equ timestr - hours ; hours len -> the max number of digits
107
-
108
-	time_res: dq 2 ; 2 digits bellow seconds can grow to 8
122
+	faultmsg: db "Fault !", 0xA
123
+	faultmsglen: equ $ - faultmsg
109
 
124
 
110
 	nl: db 0x0A
125
 	nl: db 0x0A
111
 	cr: db 0xd
126
 	cr: db 0xd
112
-	buf: db 0
113
-
114
-	lapsmsg: db "Lap : "
115
-	lapsmsglen: equ $ - lapsmsg
116
 
127
 
117
-	lapcount: db "00000000"
118
-	lapcountlen: equ $ - lapcount
119
-	laplen: dq 2
120
-
121
-	fcntl_flag: dq 0
122
 
128
 
123
 section .text
129
 section .text
124
 global _start
130
 global _start
128
 jmp arg_parse
134
 jmp arg_parse
129
 arg_ok:
135
 arg_ok:
130
 
136
 
131
-; set stdin non blocking
137
+; set stdin reads non blocking
132
 xor rdx, rdx
138
 xor rdx, rdx
133
 xor rdi, rdi
139
 xor rdi, rdi
134
 mov rax, 72 ; fcntl
140
 mov rax, 72 ; fcntl
136
 syscall
142
 syscall
137
 mov [fcntl_flag], rax
143
 mov [fcntl_flag], rax
138
 mov rdx, rax
144
 mov rdx, rax
139
-or rdx, 0x800 ; O_NONBLOCK
145
+or rdx, O_NONBLOCK
140
 mov rax, 72 ; fcntl
146
 mov rax, 72 ; fcntl
141
 mov rsi, 4 ; F_SETFL
147
 mov rsi, 4 ; F_SETFL
142
 syscall
148
 syscall
173
 
179
 
174
 ; set value for ts_sleep.tv_nsec given time_res
180
 ; set value for ts_sleep.tv_nsec given time_res
175
 ; div sleep time by 10 for each digits added bellow seconds
181
 ; div sleep time by 10 for each digits added bellow seconds
182
+mov qword [ts_sleep.tv_sec], 0
176
 mov rax, 100000000
183
 mov rax, 100000000
177
 mov r8, [time_res]
184
 mov r8, [time_res]
178
 mov r9, 10
185
 mov r9, 10
358
 
365
 
359
 	mov rax, 1 ; write
366
 	mov rax, 1 ; write
360
 	mov rdi, [rsp + 16] ; fd as 2nd argument
367
 	mov rdi, [rsp + 16] ; fd as 2nd argument
361
-	mov rdx, timestrlen + 9
368
+	mov rdx, timestrlen + hourslen
362
 	sub rdx, rcx ; timestr + hours len
369
 	sub rdx, rcx ; timestr + hours len
363
 	lea rsi, [hours + rcx] ; hours start pointer
370
 	lea rsi, [hours + rcx] ; hours start pointer
364
 	syscall
371
 	syscall

Loading…
Cancel
Save