Browse Source

Factorisation + enhancement in proc_print_time

Writing a proc_nl function to print a newline on a given fd
Enhancement in argument passing to proc_print_time
Yann Weber 6 years ago
parent
commit
31a4276fa3
1 changed files with 23 additions and 30 deletions
  1. 23
    30
      wtfstopw.asm

+ 23
- 30
wtfstopw.asm View File

187
 mov [ts_sleep.tv_nsec], rax
187
 mov [ts_sleep.tv_nsec], rax
188
 
188
 
189
 main_loop:
189
 main_loop:
190
-	push 2 ; stderr
191
-	push 0x0D ; \r
190
+	mov rax, 2 ; stderr
191
+	mov rdi, 0xD ; \r
192
 	call proc_print_time
192
 	call proc_print_time
193
 
193
 
194
 	; Attempt to read from stdin
194
 	; Attempt to read from stdin
240
 	pop rdi ; return code
240
 	pop rdi ; return code
241
 	syscall
241
 	syscall
242
 fault:
242
 fault:
243
-	mov rax, 1 ; write
244
 	mov rdi, 2 ; stderr
243
 	mov rdi, 2 ; stderr
245
-	mov rsi, nl
246
-	mov rdx, 1
247
-	syscall
244
+	call proc_nl
248
 	mov rax, 1
245
 	mov rax, 1
249
 	mov rsi, faultmsg
246
 	mov rsi, faultmsg
250
 	mov rdx, faultmsglen
247
 	mov rdx, faultmsglen
254
 	jmp exit
251
 	jmp exit
255
 
252
 
256
 newline_exit:
253
 newline_exit:
257
-	mov rax, 1
258
 	mov rdi, 1
254
 	mov rdi, 1
259
-	mov rsi, nl
260
-	mov rdx, 1
261
-	syscall
255
+	call proc_nl
262
 
256
 
263
 	mov rdi, 0 ; exit OK
257
 	mov rdi, 0 ; exit OK
264
 	jmp exit
258
 	jmp exit
266
 ;
260
 ;
267
 ; Print current time on FD and add a leading char CHR
261
 ; Print current time on FD and add a leading char CHR
268
 ; push FD & push CHR to set arguments
262
 ; push FD & push CHR to set arguments
263
+; rax the FS & rdi the leading CHR
269
 ;
264
 ;
270
 proc_print_time:
265
 proc_print_time:
271
-	; push ret addr before arguments
272
-	pop r8
273
-	pop r9
274
-	pop r10
275
-	push r8
276
-	push r10
277
-	push r9
266
+	
267
+	push rax
268
+	push rdi
278
 
269
 
279
 	; updating ts_cur time
270
 	; updating ts_cur time
280
 	mov rax, 228 ; clock_gettime
271
 	mov rax, 228 ; clock_gettime
284
 
275
 
285
 	; Calculating elapsed ns
276
 	; Calculating elapsed ns
286
 	mov rax, [ts_cur.tv_nsec]
277
 	mov rax, [ts_cur.tv_nsec]
287
-	mov rbx, [ts_start.tv_nsec]
288
-	sub rax, rbx
278
+	sub rax, [ts_start.tv_nsec]
289
 	cmp rax, 0
279
 	cmp rax, 0
290
 	jge print_time_us_cont
280
 	jge print_time_us_cont
291
 	; negativ result
281
 	; negativ result
292
 	add rax, 1000000000
282
 	add rax, 1000000000
293
-	mov rbx, [ts_cur.tv_sec]
294
-	sub rbx, 1
295
-	mov [ts_cur.tv_sec], rbx
283
+	sub qword [ts_cur.tv_sec], 1
284
+
296
 	print_time_us_cont:
285
 	print_time_us_cont:
297
-	
298
 	; Divide result given time_res
286
 	; Divide result given time_res
299
 	mov r10, rax
287
 	mov r10, rax
300
 	mov rax, 1000000000
288
 	mov rax, 1000000000
459
 	mov rdx, 3 ; " : "
447
 	mov rdx, 3 ; " : "
460
 	syscall
448
 	syscall
461
 
449
 
462
-	push 1 ; stdout
463
-	push 0x0A ; \n
450
+	mov rax, 1 ; stdout
451
+	mov rdi, 0xA ; \n
464
 	call proc_print_time
452
 	call proc_print_time
465
 
453
 
466
 	ret
454
 	ret
550
 	call proc_strlen
538
 	call proc_strlen
551
 	mov rax, 1
539
 	mov rax, 1
552
 	syscall
540
 	syscall
553
-	mov rax, 1
554
-	mov rsi, nl
555
-	mov rdx, 1
556
-	syscall
557
-	syscall
541
+	call proc_nl
542
+	call proc_nl
558
 	jmp arg_err
543
 	jmp arg_err
559
 
544
 
560
 ;
545
 ;
600
 	mov rdx, r9
585
 	mov rdx, r9
601
 	ret
586
 	ret
602
 
587
 
588
+; with rdi the fd
589
+proc_nl:
590
+	mov rax, 1
591
+	mov rsi, nl
592
+	mov rdx, 1
593
+	syscall
594
+	ret
595
+
603
 .end:
596
 .end:

Loading…
Cancel
Save