azan

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

commit 079de84867644f9882a8d6089f021b4aad31af14
parent acf99376cac9cea7316cc25185621f378e0af26a
Author: afify <hassan@afify.dev>
Date:   Sat, 21 Nov 2020 05:15:19 +0300

[feat] print left duration, fajr & duhr

- test fajr duhr
- print fajr duhr
- add res_msg
- calculate diff
- set msg digits
- print msg and exit

Diffstat:
Mazan-nasm.s | 49++++++++++++++++++++++++++++---------------------
Mmacros.s | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 82 insertions(+), 29 deletions(-)

diff --git a/azan-nasm.s b/azan-nasm.s @@ -28,11 +28,12 @@ section .rodata pray_1: dq 0x4038000000000000 ;double 24.0 neg1: dq 0xBFF0000000000000 ;double -1.0 p1: dq 0X3fb1111111111111 ;double 0.066666666666666666 - hours_to_sec: dq 0x40ac200000000000 ;double 3600 + sec_inhour: dq 0x40ac200000000000 ;double 3600 + sec_inmin: dq 0x404e000000000000 ;double 60 section .bss - tmp0: resq 1 - tmp1: resq 1 + tmp0: resq 1 + tmp1: resq 1 section .text global _start @@ -77,7 +78,7 @@ get_timestamp: sub eax, edx cvtsi2sd xmm15, rdx movsd xmm14, [time_zone] - mulsd xmm14, [hours_to_sec] + mulsd xmm14, [sec_inhour] subsd xmm15, xmm14 ;tstamp = xmm6 convert tstamp to double @@ -215,30 +216,34 @@ get_fajr: ;fajr = duhr - T(fajr_angle, D); movsd xmm3, xmm0 subsd xmm3, xmm4 -convert_fajr_to_time: - mulsd xmm3, [hours_to_sec] ;convert to seconds +test_fajr: + mulsd xmm3, [sec_inhour] ;convert to seconds roundsd xmm3, xmm3, ROUND_DOWN addsd xmm3, xmm15 ;fajr seconds + start_of_day ucomisd xmm3, xmm6 ;if fajr > tstamp - jae calculate_left_fajr - jmp convert_duhr_to_time + jae print_fajr + jmp test_duhr -convert_duhr_to_time: - mulsd xmm0, [hours_to_sec] ;convert to seconds +test_duhr: + mulsd xmm0, [sec_inhour] ;convert to seconds roundsd xmm0, xmm0, ROUND_DOWN addsd xmm0, xmm15 ;duhr seconds + start_of_day ucomisd xmm0, xmm6 ;if duhr > tstamp - jae calculate_left_duhr - jmp calculate_asr - -calculate_left_fajr: - DIE fajr_msg, fajr_len -; -calculate_left_duhr: - DIE duhr_msg, duhr_len -; -calculate_asr: - DIE asr_msg, asr_len + jae print_duhr + jmp get_asr + +print_fajr: + mov [res_msg], byte 'F' + CALC_DIFF xmm3 + PRINT_EXIT + +print_duhr: + mov [res_msg], byte 'D' + CALC_DIFF xmm0 + PRINT_EXIT + +get_asr: + PRINT_EXIT ; duhr: ; xmm0 ; p2: ; xmm1 @@ -247,6 +252,8 @@ calculate_asr: ; tstamp: ; xmm6 ; EqT: ; xmm9 ; D: ; xmm8 +; result_hour ; r8 +; result_min ; r9 ; start_of_day: ; xmm15 EEXIT EXIT_SUCCESS diff --git a/macros.s b/macros.s @@ -17,14 +17,9 @@ section .rodata version_msg: db "azan-nasm-", VERSION, 10, 0 version_len: equ $ - version_msg - fajr_msg: db "fajr is bigger", 10, 0 - fajr_len: equ $ - fajr_msg - - duhr_msg: db "duhr is bigger", 10, 0 - duhr_len: equ $ - duhr_msg - - asr_msg: db "asr is bigger", 10, 0 - asr_len: equ $ - asr_msg +section .data + res_msg: db "X XX:XX", 10, 0 + res_len: equ $ - res_msg %macro CHECK_OPENBSD 0 %ifdef OpenBSD @@ -50,6 +45,16 @@ section .note.openbsd.ident note EEXIT EXIT_FAILURE %endmacro +%macro PRINT_EXIT 0 + SET_MSG + mov rax, SYS_write + mov rdi, STDOUT + mov rsi, res_msg + mov rdx, res_len + syscall + EEXIT EXIT_SUCCESS +%endmacro + %macro ACOS 1 ;acos(x) = atan(sqrt((1-x*x)/(x*x))) movsd [tmp0], %1 fld qword [tmp0] @@ -103,4 +108,45 @@ section .note.openbsd.ident note movsd %1, [tmp0] %endmacro +%macro CALC_DIFF 1 + ; diff = prayer time - tstamp + subsd %1, xmm6 + + ;hours = floor(diff / sec_inhour) = xmm13 + movsd xmm13, %1 + divsd xmm13, [sec_inhour] + roundsd xmm13, xmm13, ROUND_DOWN + cvtsd2si r8, xmm13 + + ;remaining_seconds = diff - (hours * sec_inhour) = xmm14 + movsd xmm14, %1 + mulsd xmm13, [sec_inhour] + subsd xmm14, xmm13 + + ;minutes = remaining_seconds / sec_inmin + divsd xmm14, [sec_inmin] + roundsd xmm14, xmm14, ROUND_DOWN + cvtsd2si r9, xmm14 +%endmacro + +%macro SET_MSG 0 + xor rdx, rdx + mov rbx, 0xa + mov rax, r8 + div ebx + add rax, 0x30 + add rdx, 0x30 + mov [res_msg+2], al + mov [res_msg+3], dl + + xor rdx, rdx + mov rbx, 10 + mov rax, r9 + div ebx + add rax, 0x30 + add rdx, 0x30 + mov [res_msg+5], al + mov [res_msg+6], dl +%endmacro + %endif ;MACROS_S