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
 
16
 
17
 ;
17
 ;
18
 ; A simple precise stopwatch
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
 ; Usage : ./wtfstopw
22
 ; Usage : ./wtfstopw
22
 ;	press enter to exit
23
 ;	press enter to exit
25
 
26
 
26
 [bits 64]
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
 	sigaction: ISTRUC SIGACTION_STRUC
53
 	sigaction: ISTRUC SIGACTION_STRUC
54
 		at  SIGACTION_STRUC.sa_handler, dq 0
54
 		at  SIGACTION_STRUC.sa_handler, dq 0
65
 	TIMESPEC ts_cur
65
 	TIMESPEC ts_cur
66
 
66
 
67
 	ts_sleep:
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
 	;; 1/2s sleep
71
 	;; 1/2s sleep
72
 	;ts_sleep:
72
 	;ts_sleep:
77
 	faultmsg: db "fault", 0xA
77
 	faultmsg: db "fault", 0xA
78
 	faultmsglen: equ $ - faultmsg
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
 	hours: db "000000000"
84
 	hours: db "000000000"
84
 	timestr: db ":00:00.0000    ", 0x0a
85
 	timestr: db ":00:00.0000    ", 0x0a
137
 mov rsi, ts_start
138
 mov rsi, ts_start
138
 syscall
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
 main_loop:
147
 main_loop:
141
 	push 2 ; stderr
148
 	push 2 ; stderr
142
 	push 0x0D ; \r
149
 	push 0x0D ; \r
157
 	mov rsi, 0
164
 	mov rsi, 0
158
 	syscall
165
 	syscall
159
 
166
 
160
-	jmp main_loop
167
+jmp main_loop ; main_loop
161
 
168
 
162
 flush_stdin:
169
 flush_stdin:
163
 	mov rax, 0
170
 	mov rax, 0
200
 ; Print current time on FD r10 and put r13b as leading char
207
 ; Print current time on FD r10 and put r13b as leading char
201
 ;
208
 ;
202
 proc_print_time:
209
 proc_print_time:
210
+	; push ret addr before arguments
203
 	pop r8
211
 	pop r8
204
 	pop r9
212
 	pop r9
205
 	pop r10
213
 	pop r10
206
 	push r8
214
 	push r8
207
 	push r10
215
 	push r10
208
 	push r9
216
 	push r9
217
+
209
 	; updating ts_cur time
218
 	; updating ts_cur time
210
 	mov rax, 228 ; clock_gettime
219
 	mov rax, 228 ; clock_gettime
211
 	mov rdi, 0 ; CLOCK_REALTIME
220
 	mov rdi, 0 ; CLOCK_REALTIME
212
 	mov rsi, ts_cur
221
 	mov rsi, ts_cur
213
 	syscall
222
 	syscall
214
 
223
 
224
+	; Calculating elapsed ns
215
 	mov rax, [ts_cur.tv_nsec]
225
 	mov rax, [ts_cur.tv_nsec]
216
 	mov rbx, [ts_start.tv_nsec]
226
 	mov rbx, [ts_start.tv_nsec]
217
 	sub rax, rbx
227
 	sub rax, rbx

Loading…
Cancel
Save