Browse Source

Code clean Makefile enhancement + start message

Yann Weber 5 years ago
parent
commit
2b53f54d4b
1 changed files with 36 additions and 26 deletions
  1. 36
    26
      wtfstopw.asm

+ 36
- 26
wtfstopw.asm View File

@@ -16,7 +16,8 @@
16 16
 
17 17
 ;
18 18
 ; A simple precise stopwatch
19
-; Build : nasm -felf64 wtfstopw.asm && ld wtfstopw.o -o wtfstopw
19
+; Build : nasm -felf64 wtfstopw.asm && ld -mefl_x86_64 wtfstopw.o -o wtfstopw
20
+; Build Debug : nasm -felf64 -l wtfstopw.lst wtfstopw.asm && ld -s -mefl_x86_64 wtfstopw.o -o wtfstopw
20 21
 ;
21 22
 ; Usage : ./wtfstopw
22 23
 ;	press enter to exit
@@ -25,30 +26,29 @@
25 26
 
26 27
 [bits 64]
27 28
 
28
-section .data
29
-
30
-	STRUC TIMESPEC_STRUC
31
-		.tv_sec: resq 1
32
-		.tv_nsec: resq 1
33
-	ENDSTRUC
29
+STRUC TIMESPEC_STRUC
30
+	.tv_sec: resq 1
31
+	.tv_nsec: resq 1
32
+ENDSTRUC
34 33
 
35 34
 
36
-	%macro TIMESPEC 1
37
-		%1: ISTRUC TIMESPEC_STRUC
38
-			at TIMESPEC_STRUC.tv_sec, dq 0
39
-			at TIMESPEC_STRUC.tv_nsec, dq 0
40
-		IEND
41
-		%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
42
-		%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
43
-	%endmacro
35
+%macro TIMESPEC 1
36
+	%1: ISTRUC TIMESPEC_STRUC
37
+		at TIMESPEC_STRUC.tv_sec, dq 0
38
+		at TIMESPEC_STRUC.tv_nsec, dq 0
39
+	IEND
40
+	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
41
+	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
42
+%endmacro
44 43
 
45
-	STRUC SIGACTION_STRUC
46
-		.sa_handler:      resq      1
47
-		.sa_flags:        resq      1
48
-		.sa_restorer:     resq      1
49
-		.sa_mask:         resb      128
50
-	ENDSTRUC
44
+STRUC SIGACTION_STRUC
45
+	.sa_handler:      resq      1
46
+	.sa_flags:        resq      1
47
+	.sa_restorer:     resq      1
48
+	.sa_mask:         resb      128
49
+ENDSTRUC
51 50
 
51
+section .data
52 52
 
53 53
 	sigaction: ISTRUC SIGACTION_STRUC
54 54
 		at  SIGACTION_STRUC.sa_handler, dq 0
@@ -65,8 +65,8 @@ section .data
65 65
 	TIMESPEC ts_cur
66 66
 
67 67
 	ts_sleep:
68
-		tv_sleep_s dd 0,0
69
-		tv_sleep_us dd 10000000,0 
68
+		tv_sleep_s dq 0
69
+		tv_sleep_us dq 10000000
70 70
 
71 71
 	;; 1/2s sleep
72 72
 	;ts_sleep:
@@ -77,8 +77,9 @@ section .data
77 77
 	faultmsg: db "fault", 0xA
78 78
 	faultmsglen: equ $ - faultmsg
79 79
 
80
-	msg:	db "0 Hello, world!", 10
81
-	msglen: equ $ - msg
80
+	startmsg: db "Press Enter or ctrl+d to exit and ctrl+c for new lap."
81
+	db 0xA
82
+	startmsglen: equ $ - startmsg
82 83
 
83 84
 	hours: db "000000000"
84 85
 	timestr: db ":00:00.0000    ", 0x0a
@@ -137,6 +138,12 @@ mov rdi, 0 ; CLOCK_REALTIME
137 138
 mov rsi, ts_start
138 139
 syscall
139 140
 
141
+mov rax, 1 ; write
142
+mov rdi, 2 ; stderr
143
+mov rsi, startmsg
144
+mov rdx, startmsglen
145
+syscall
146
+
140 147
 main_loop:
141 148
 	push 2 ; stderr
142 149
 	push 0x0D ; \r
@@ -157,7 +164,7 @@ main_loop:
157 164
 	mov rsi, 0
158 165
 	syscall
159 166
 
160
-	jmp main_loop
167
+jmp main_loop ; main_loop
161 168
 
162 169
 flush_stdin:
163 170
 	mov rax, 0
@@ -200,18 +207,21 @@ newline_exit:
200 207
 ; Print current time on FD r10 and put r13b as leading char
201 208
 ;
202 209
 proc_print_time:
210
+	; push ret addr before arguments
203 211
 	pop r8
204 212
 	pop r9
205 213
 	pop r10
206 214
 	push r8
207 215
 	push r10
208 216
 	push r9
217
+
209 218
 	; updating ts_cur time
210 219
 	mov rax, 228 ; clock_gettime
211 220
 	mov rdi, 0 ; CLOCK_REALTIME
212 221
 	mov rsi, ts_cur
213 222
 	syscall
214 223
 
224
+	; Calculating elapsed ns
215 225
 	mov rax, [ts_cur.tv_nsec]
216 226
 	mov rbx, [ts_start.tv_nsec]
217 227
 	sub rax, rbx

Loading…
Cancel
Save