azan

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

commit 69a1711fe368ea66cff341eb76606a1d29316169
parent d538831f2c18d531f9dd8c80e9df42ac13edcb07
Author: afify <hassan@afify.dev>
Date:   Thu, 26 Nov 2020 09:16:59 +0300

[feat] add option -U print all prayers unix-time

Diffstat:
MREADME.md | 1+
Mazan-nasm.1 | 5++++-
Mazan-nasm.s | 29++++++++++++++++++++++++++++-
Mmacros.s | 31+++++++++++--------------------
4 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md @@ -44,6 +44,7 @@ $ man azan-nasm |:------:|:---------------------------------------------| | `-N` | print next prayer time, 12-hour clock format.| | `-n` | print next prayer time, 24-hour clock format.| +| `-U` | print all prayers time, unix-time format. | | `-u` | print next prayer time, unix-time format. | | `-v` | print version. | diff --git a/azan-nasm.1 b/azan-nasm.1 @@ -3,7 +3,7 @@ azan\-nasm \- simple muslim prayers calculator .SH SYNOPSIS .B azan\-nasm -.RB [ \-Nnuv ] +.RB [ \-NnUuv ] .SH DESCRIPTION azan\-nasm is a simple muslim prayers calculator for unix-like systems. Show prayers time. written in nasm x86-64. .SH OPTIONS @@ -14,6 +14,9 @@ print next prayer time, 12-hour clock format. .B \-n print next prayer time, 24-hour clock format. .TP +.B \-U +print all prayers time, unix-time format. +.TP .B \-u print next prayer time, unix-time format. .TP diff --git a/azan-nasm.s b/azan-nasm.s @@ -35,6 +35,14 @@ section .rodata maghrib_2: dq 0x3feaaaaaaaaaaaab ;double 0.833333333333333333 isha_nor: dq 0x40b5180000000000 ;double 5400.0 90 min isha_ram: dq 0x40bc200000000000 ;double 7200.0 120 min + usage_msg: db "usage: azan-nasm [-NnUuv]", 10, 0 + usage_len: equ $ - usage_msg + version_msg: db "azan-nasm-", VERSION, 10, 0 + version_len: equ $ - version_msg + +section .data + res_msg: db "X XX:XX", 10, 0 + res_len: equ $ - res_msg section .bss tmp0: resq 1 @@ -59,6 +67,8 @@ check_argv: cmp [r11+2], byte 0x00 jne die_usage mov r12b, [r11+1] + cmp r12b, 0x55 ;U + je get_timestamp cmp r12b, 0x75 ;u je get_timestamp cmp r12b, 0x6e ;n @@ -204,6 +214,8 @@ test_duhr: mulsd xmm0, [sec_inhour] ;convert to seconds roundsd xmm0, xmm0, ROUND_DOWN addsd xmm0, xmm15 ;duhr seconds + start_of_day + cmp r12b, byte 'U' + je get_asr ucomisd xmm0, xmm6 ;if duhr > tstamp jae print_duhr @@ -240,6 +252,8 @@ test_asr: mulsd xmm4, [sec_inhour] ;convert to seconds roundsd xmm4, xmm4, ROUND_DOWN addsd xmm4, xmm15 ;asr seconds + start_of_day + cmp r12b, byte 'U' + je get_maghrib ucomisd xmm4, xmm6 ;if asr > tstamp jae print_asr @@ -254,6 +268,8 @@ test_maghrib: mulsd xmm5, [sec_inhour] ;convert to seconds roundsd xmm5, xmm5, ROUND_DOWN addsd xmm5, xmm15 ;maghrib seconds + start_of_day + cmp r12b, byte 'U' + je get_isha ucomisd xmm5, xmm6 ;if maghrib > tstamp jae print_maghrib @@ -281,6 +297,8 @@ calc_isha_nor: ;duhr + T(isha_angle, D); NORM xmm7, [pray_1] test_isha: + cmp r12b, byte 'U' + je print_all_u ucomisd xmm7, xmm6 ;if isha > tstamp jae print_isha @@ -322,7 +340,8 @@ print_isha: PRINT_FLAG xmm7 print_unix: - PRINT_INT ;from xmm14 + PRINT_INT xmm14 + EEXIT EXIT_SUCCESS print_24: subsd xmm14, xmm15 ;prayer timestamp - start_of_day @@ -340,6 +359,14 @@ sub12h: sub r8, 0xc PRINT_EXIT +print_all_u: + PRINT_INT xmm3 ;fajr + PRINT_INT xmm0 ;duhr + PRINT_INT xmm4 ;asr + PRINT_INT xmm5 ;maghrib + PRINT_INT xmm7 ;isha + EEXIT EXIT_SUCCESS + ; result_hour ;r8 ; result_min ;r9 ; duhr_ts: ;xmm0 diff --git a/macros.s b/macros.s @@ -11,16 +11,6 @@ %define ROUND_DOWN 01B ;toward -inf %define MAX_ARGC 2 -section .rodata - usage_msg: db "usage: azan-nasm [-Nnuv]", 10, 0 - usage_len: equ $ - usage_msg - version_msg: db "azan-nasm-", VERSION, 10, 0 - version_len: equ $ - version_msg - -section .data - res_msg: db "X XX:XX", 10, 0 - res_len: equ $ - res_msg - %macro CHECK_OPENBSD 0 %ifdef OpenBSD section .note.openbsd.ident note @@ -141,13 +131,21 @@ section .note.openbsd.ident note mulsd %1, [p1] %endmacro -%macro PRINT_INT 0 +%macro PRINT_INT 1 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 + cvttsd2si rax, %1 ; convert double to int mov rbx, 0xa ; hex number will divide to 10 mov rcx, 1 ; decimal number length + '\n' + call 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 +%endmacro next_digit: inc rcx ; calculate output length @@ -158,14 +156,7 @@ next_digit: 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 + ret %macro PRINT_FLAG 1 movsd xmm14, %1 ;copy prayer to xmm14