Browse Source

Using struc for timespec + move data section

Yann Weber 5 years ago
parent
commit
540c840d87
1 changed files with 52 additions and 40 deletions
  1. 52
    40
      wtfstopw.asm

+ 52
- 40
wtfstopw.asm View File

20
 
20
 
21
 [bits 64]
21
 [bits 64]
22
 
22
 
23
+section .data
24
+
25
+	STRUC TIMESPEC_STRUC
26
+		.tv_sec: resq 1
27
+		.tv_nsec: resq 1
28
+	ENDSTRUC
29
+
30
+
31
+	%macro TIMESPEC 1
32
+		%1: ISTRUC TIMESPEC_STRUC
33
+			at TIMESPEC_STRUC.tv_sec, dq 0
34
+			at TIMESPEC_STRUC.tv_nsec, dq 0
35
+		IEND
36
+		%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
37
+		%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
38
+	%endmacro
39
+
40
+	TIMESPEC ts_start
41
+	TIMESPEC ts_cur
42
+
43
+	ts_sleep:
44
+		tv_sleep_s dd 0,0
45
+		tv_sleep_us dd 10000000,0 
46
+
47
+
48
+	;; 1/2s sleep
49
+	;ts_sleep:
50
+	;	tv_sleep_s dq 0
51
+	;	tv_sleep_us dq 500000000
52
+
53
+
54
+	faultmsg: db "fault", 0xA
55
+	faultmsglen: equ $ - faultmsg
56
+
57
+	msg:	db "0 Hello, world!", 10
58
+	msglen: equ $ - msg
59
+
60
+	hours: db "000000000"
61
+	timestr: db ":00:00.0000    ", 0x0D
62
+	timestrlen: equ $ - timestr
63
+
64
+	nl: db 0x0A
65
+	buf: db 0
66
+
67
+
68
+
23
 section .text
69
 section .text
24
 global _start
70
 global _start
25
 
71
 
53
 	mov rsi, ts_cur
99
 	mov rsi, ts_cur
54
 	syscall
100
 	syscall
55
 
101
 
56
-	mov rax, [tv_cur_us]
57
-	mov rbx, [tv_start_us]
102
+	mov rax, [ts_cur.tv_nsec]
103
+	mov rbx, [ts_start.tv_nsec]
58
 	sub rax, rbx
104
 	sub rax, rbx
59
 	cmp rax, 0
105
 	cmp rax, 0
60
 	jge print_time_us_cont
106
 	jge print_time_us_cont
61
 	; negativ result
107
 	; negativ result
62
 	add rax, 1000000000
108
 	add rax, 1000000000
63
-	mov rbx, [tv_cur_s]
109
+	mov rbx, [ts_cur.tv_sec]
64
 	sub rbx, 1
110
 	sub rbx, 1
65
-	mov [tv_cur_s], rbx
111
+	mov [ts_cur.tv_sec], rbx
66
 	print_time_us_cont:
112
 	print_time_us_cont:
67
 	xor rdx, rdx
113
 	xor rdx, rdx
68
 	mov rcx, 100000
114
 	mov rcx, 100000
83
 		jg print_time_us_loop
129
 		jg print_time_us_loop
84
 
130
 
85
 	; handling seconds, minutes & hours
131
 	; handling seconds, minutes & hours
86
-	mov rax, [tv_cur_s]
87
-	mov rbx, [tv_start_s]
132
+	mov rax, [ts_cur.tv_sec]
133
+	mov rbx, [ts_start.tv_sec]
88
 	sub rax, rbx
134
 	sub rax, rbx
89
 	; rax now contain elapsed seconds
135
 	; rax now contain elapsed seconds
90
 	; filling timestr with seconds & minutes
136
 	; filling timestr with seconds & minutes
211
 	syscall
257
 	syscall
212
 	jmp exit
258
 	jmp exit
213
 
259
 
214
-
215
-section .data
216
-
217
-ts_start:
218
-	tv_start_s dq 0
219
-	tv_start_us dq 0
220
-
221
-faultmsg: db "fault", 0xA
222
-faultmsglen: equ $ - faultmsg
223
-
224
-msg:	db "0 Hello, world!", 10
225
-msglen: equ $ - msg
226
-
227
-hours: db "000000000"
228
-timestr: db ":00:00.0000    ", 0x0D
229
-timestrlen: equ $ - timestr
230
-
231
-nl: db 0x0A
232
-buf: db 0
233
-
234
-ts_cur:
235
-	tv_cur_s dq 0
236
-	tv_cur_us dq 0
237
-
238
-ts_sleep:
239
-	tv_sleep_s dd 0,0
240
-	tv_sleep_us dd 10000000,0 
241
-
242
-
243
-;; 1/2s sleep
244
-;ts_sleep:
245
-;	tv_sleep_s dq 0
246
-;	tv_sleep_us dq 500000000
247
-
248
 .end:
260
 .end:

Loading…
Cancel
Save