Browse Source

Enhancement in file header

Moved the macro before .data section
Add a .bss section
Reorganisation of .data section
Yann Weber 5 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,21 +26,20 @@
26 26
 ; Interact :
27 27
 ; 	press enter to exit
28 28
 ; 	send SIGINT (with kill -2 ir ctrl + c) for a new lap
29
-
30
-
31
-
32 29
 [bits 64]
33 30
 
31
+%define O_NONBLOCK 0x800
32
+
34 33
 STRUC TIMESPEC_STRUC
35 34
 	.tv_sec: resq 1
36 35
 	.tv_nsec: resq 1
37 36
 ENDSTRUC
38 37
 
39 38
 
40
-%macro TIMESPEC 3
39
+%macro TIMESPEC 1
41 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 43
 	IEND
45 44
 	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
46 45
 	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
@@ -53,9 +52,9 @@ STRUC SIGACTION_STRUC
53 52
 	.sa_mask:         resb      128
54 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 58
 		at  SIGACTION_STRUC.sa_handler, dq 0
60 59
 		at  SIGACTION_STRUC.sa_flags, dq 0
61 60
 		at  SIGACTION_STRUC.sa_restorer, dq 0
@@ -65,14 +64,34 @@ section .data
65 64
 	%define sigaction.sa_flags sigaction+SIGACTION_STRUC.sa_flags
66 65
 	%define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
67 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 96
 	startmsg: db "Press Enter or ctrl+d to exit and ctrl+c for new lap."
78 97
 	db 0xA
@@ -100,25 +119,12 @@ section .data
100 119
 	badval_msg: db "Value for -r should be in [1..8] but got "
101 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 125
 	nl: db 0x0A
111 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 129
 section .text
124 130
 global _start
@@ -128,7 +134,7 @@ _start:
128 134
 jmp arg_parse
129 135
 arg_ok:
130 136
 
131
-; set stdin non blocking
137
+; set stdin reads non blocking
132 138
 xor rdx, rdx
133 139
 xor rdi, rdi
134 140
 mov rax, 72 ; fcntl
@@ -136,7 +142,7 @@ mov rsi, 3 ; F_GETFL
136 142
 syscall
137 143
 mov [fcntl_flag], rax
138 144
 mov rdx, rax
139
-or rdx, 0x800 ; O_NONBLOCK
145
+or rdx, O_NONBLOCK
140 146
 mov rax, 72 ; fcntl
141 147
 mov rsi, 4 ; F_SETFL
142 148
 syscall
@@ -173,6 +179,7 @@ syscall
173 179
 
174 180
 ; set value for ts_sleep.tv_nsec given time_res
175 181
 ; div sleep time by 10 for each digits added bellow seconds
182
+mov qword [ts_sleep.tv_sec], 0
176 183
 mov rax, 100000000
177 184
 mov r8, [time_res]
178 185
 mov r9, 10
@@ -358,7 +365,7 @@ proc_print_time:
358 365
 
359 366
 	mov rax, 1 ; write
360 367
 	mov rdi, [rsp + 16] ; fd as 2nd argument
361
-	mov rdx, timestrlen + 9
368
+	mov rdx, timestrlen + hourslen
362 369
 	sub rdx, rcx ; timestr + hours len
363 370
 	lea rsi, [hours + rcx] ; hours start pointer
364 371
 	syscall

Loading…
Cancel
Save