azan

prayers time calculator written in nasm
git clone git://git.afify.dev/azan
Log | Files | Refs | README | LICENSE

commit 86150536c7aeeb09a91df35c8767bc93df434a21
parent 61da4b64540673cf0334941e3e65a17230e2f27d
Author: afify <hassan@afify.dev>
Date:   Tue, 24 Nov 2020 09:19:40 +0300

[feat] add option -u print next in timestamp

Diffstat:
Mazan-nasm.s | 36++++++++++++++++++++++++++++++------
Mmacros.s | 28+++++++++++++++++++++++++++-
2 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/azan-nasm.s b/azan-nasm.s @@ -46,18 +46,21 @@ _start: pop rcx cmp rcx, MAX_ARGC jl get_timestamp - je die_version + je check_argv die_usage: DIE usage_msg, usage_len -die_version: - mov rcx, [rsp+8] ;argv - cmp [rcx], byte '-' +check_argv: + mov r11, [rsp+8] ;argv + cmp [r11], byte 0x2d ;- jne die_usage - cmp [rcx+1], byte 'v' + cmp [r11+2], byte 0x00 jne die_usage - cmp [rcx+2], byte 0 + mov r12b, [r11+1] + cmp r12b, 0x75 ;u + je get_timestamp + cmp r12b, 0x76 ;v jne die_usage DIE version_msg, version_len @@ -282,34 +285,55 @@ get_nfajr: ;fajr + sec_inday print_nfajr: mov [res_msg], byte 'F' + movsd xmm14, xmm12 + cmp r12b, byte 'u' + je print_unix CALC_DIFF xmm12 PRINT_EXIT print_fajr: mov [res_msg], byte 'F' + movsd xmm14, xmm3 + cmp r12b, byte 'u' + je print_unix CALC_DIFF xmm3 PRINT_EXIT print_duhr: mov [res_msg], byte 'D' + movsd xmm14, xmm0 + cmp r12b, byte 'u' + je print_unix CALC_DIFF xmm0 PRINT_EXIT print_asr: mov [res_msg], byte 'A' + movsd xmm14, xmm4 + cmp r12b, byte 'u' + je print_unix CALC_DIFF xmm4 PRINT_EXIT print_maghrib: mov [res_msg], byte 'M' + movsd xmm14, xmm5 + cmp r12b, byte 'u' + je print_unix CALC_DIFF xmm5 PRINT_EXIT print_isha: mov [res_msg], byte 'I' + movsd xmm14, xmm7 + cmp r12b, byte 'u' + je print_unix CALC_DIFF xmm7 PRINT_EXIT +print_unix: + PRINT_INT ;from xmm14 + ; result_hour ;r8 ; result_min ;r9 ; duhr_ts: ;xmm0 diff --git a/macros.s b/macros.s @@ -12,7 +12,7 @@ %define MAX_ARGC 2 section .rodata - usage_msg: db "usage: azan-nasm [-v]", 10, 0 + usage_msg: db "usage: azan-nasm [-uv]", 10, 0 usage_len: equ $ - usage_msg version_msg: db "azan-nasm-", VERSION, 10, 0 version_len: equ $ - version_msg @@ -197,4 +197,30 @@ section .note.openbsd.ident note mulsd %1, [p1] %endmacro +%macro PRINT_INT 0 + nop + mov rsi, tmp0+11 ; pointer to the end of decimal number + mov byte [rsi], 0xa ; add '\n' + cvttsd2si rax, xmm14 ; convert double to int + mov rbx, 0xa ; hex number will divide to 10 + mov rcx, 1 ; decimal number length + '\n' + +next_digit: + inc rcx ; calculate output length + xor rdx, rdx ; remainder storage should be 0 before divide + div rbx ; divide hex number to 10 + add rdx, 0x30 ; calculate ascii code of remainder + dec rsi ; calculate decimal digit place + mov [rsi], dl ; put decimal digit into string + cmp rax, 0 ; is there hex digits any more? + jnz next_digit + + ;print + mov rax, SYS_write ; system call number (sys_write) + mov rdi, STDOUT ; first argument: file handle (stdout) + mov rdx, rcx ; second argument: pointer to string + syscall + EEXIT EXIT_SUCCESS +%endmacro + %endif ;MACROS_S