From eafb19672c0399033d6f94fbf1fe63a0999d9693 Mon Sep 17 00:00:00 2001 From: Yann Weber Date: Tue, 21 Aug 2018 07:48:37 +0200 Subject: [PATCH] First commit for asm implementation --- wtfstopw.asm | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 wtfstopw.asm diff --git a/wtfstopw.asm b/wtfstopw.asm new file mode 100644 index 0000000..6655e44 --- /dev/null +++ b/wtfstopw.asm @@ -0,0 +1,134 @@ +[bits 64] + +section .text +global _start + +_start: + +; set stdin non blocking +mov rax, 72 ; fcntl +mov rdi, 0 ; stdin +mov rsi, 3 ; F_GETFL +mov rdx, 0 +syscall +mov rdx, rax +or rdx, 4 ; O_NONBLOCK +mov rax, 72 ; fcntl +mov rdi, 0 ; stdin +mov rsi, 4 ; F_SETFL +syscall + +mov rax, 228 ; clock_gettime +mov rdi, 0 ; CLOCK_REALTIME +mov rsi, ts_start +syscall + + +print_time: + +mov rax, 228 ; clock_gettime +mov rdi, 0 ; CLOCK_REALTIME +mov rsi, ts_cur +syscall + +mov rax, [tv_cur_s] +mov rbx, [tv_start_s] +sub rax, rbx +fifoo: +add al, 0x30 +mov byte [msg], al +;xor rax, rax +;mov al, byte [msg] +;mov rdi, [tv_cur_s] +;mov rdx, [tv_start_s] +;sub rdi, rdx +;fifoo: +;add rax, rdi +;mov byte [msg], al + +mov rax, 1 +mov rdi, 1 +mov rsi, msg +mov rdx, msglen +syscall + +sleep: +mov rax, 35 +mov rdi, ts_sleep +mov rsi, 0 +syscall +jmp print_time + +mov rax, 60 ; sys_exit +mov rdi, 0 ; 0 +syscall + +dumprax: + push rax + loopdump: + push rax + mov rbx, rax + and rbx, 0x0F + cmp bl, 0xA + jge hexdigit + add bl, 0x30 + jmp loopcont + hexdigit: + sub bl, 10 + add bl, 0x41 + loopcont: +dbg: + mov byte [digit], bl + mov rax, 1 + mov rdi, 1 + mov rsi, digit + mov rdx, 1 + syscall + pop rax + mov rdi, 10 + xor rdx, rdx + mov rsi, rax + div rdi + cmp rax, 10 + jge loopdump + + mov al, 10 + mov al, [digit] + mov rax, 1 + mov rdi, 1 + mov rsi, nl + mov rdx, 1 + syscall + + pop rax +ret + +section .data +foobar: ISTRUC timespec +ts_start: + tv_start_s dq 0 + tv_start_us dq 0 + + +msg: db "0 Hello, world!", 10 +msglen: equ $ - msg + +digit: db "0" +nl: db 10 + +ts_cur: + tv_cur_s dq 0 + tv_cur_us dq 0 + +;ts_sleep: +; tv_sleep_s dd 0,0 +; tv_sleep_us dd 10000000,0 + + +; 1/2s sleep +ts_sleep: + tv_sleep_s dq 0 + tv_sleep_us dq 500000000 + + +.end: