From 6e9b7a500c3db8f880cc096fbb286bc3c1713b9f Mon Sep 17 00:00:00 2001 From: afify Date: Thu, 26 Nov 2020 10:33:51 +0300 Subject: [PATCH] [feat] add option -a print all prayers 24-hour --- README.md | 3 +- azan-nasm.1 | 3 ++ azan-nasm.s | 102 +++++++++++++++++++++++++++++++++++++++++++----------------- macros.s | 6 ++-- 4 files changed, 81 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c6edd18..635242c 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,12 @@ $ azan-nasm Options ------- ```sh -$ azan-nasm [-Nnuv] +$ azan-nasm [-aNnUuv] $ man azan-nasm ``` | option | description | |:------:|:---------------------------------------------| +| `-a` | print all prayers time, 24-hour clock format.| | `-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. | diff --git a/azan-nasm.1 b/azan-nasm.1 index 2fd672b..5b839b3 100644 --- a/azan-nasm.1 +++ b/azan-nasm.1 @@ -8,6 +8,9 @@ azan\-nasm \- simple muslim prayers calculator azan\-nasm is a simple muslim prayers calculator for unix-like systems. Show prayers time. written in nasm x86-64. .SH OPTIONS .TP +.B \-a +print all prayers time, 24-hour clock format. +.TP .B \-N print next prayer time, 12-hour clock format. .TP diff --git a/azan-nasm.s b/azan-nasm.s index 7badbc6..9446b5d 100644 --- a/azan-nasm.s +++ b/azan-nasm.s @@ -35,7 +35,7 @@ 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_msg: db "usage: azan-nasm [-aNnUuv]", 10, 0 usage_len: equ $ - usage_msg version_msg: db "azan-nasm-", VERSION, 10, 0 version_len: equ $ - version_msg @@ -67,6 +67,8 @@ check_argv: cmp [r11+2], byte 0x00 jne die_usage mov r12b, [r11+1] + cmp r12b, 0x61 ;a + je get_timestamp cmp r12b, 0x55 ;U je get_timestamp cmp r12b, 0x75 ;u @@ -206,6 +208,10 @@ test_fajr: mulsd xmm3, [sec_inhour] ;convert to seconds roundsd xmm3, xmm3, ROUND_DOWN addsd xmm3, xmm15 ;fajr seconds + start_of_day + cmp r12b, byte 'U' + je test_duhr + cmp r12b, byte 'a' + je test_duhr ucomisd xmm3, xmm6 ;if fajr > tstamp jae print_fajr @@ -214,8 +220,10 @@ 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 + cmp r12b, byte 'U' + je get_asr + cmp r12b, byte 'a' + je get_asr ucomisd xmm0, xmm6 ;if duhr > tstamp jae print_duhr @@ -252,8 +260,10 @@ 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 + cmp r12b, byte 'U' + je get_maghrib + cmp r12b, byte 'a' + je get_maghrib ucomisd xmm4, xmm6 ;if asr > tstamp jae print_asr @@ -268,8 +278,10 @@ 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 + cmp r12b, byte 'U' + je get_isha + cmp r12b, byte 'a' + je get_isha ucomisd xmm5, xmm6 ;if maghrib > tstamp jae print_maghrib @@ -299,6 +311,8 @@ calc_isha_nor: ;duhr + T(isha_angle, D); test_isha: cmp r12b, byte 'U' je print_all_u + cmp r12b, byte 'a' + je print_all_24 ucomisd xmm7, xmm6 ;if isha > tstamp jae print_isha @@ -315,49 +329,53 @@ print_nfajr: je print_fajr cmp r12b, byte 'N' je print_fajr - subsd xmm12, xmm6 ;diff = prayer time - tstamp = xmm12 + subsd xmm12, xmm6 ;diff = prayer time - tstamp = xmm12 SEC_TO_HM xmm12 - PRINT_EXIT + PRINT_HM + EEXIT EXIT_SUCCESS print_fajr: - mov [res_msg], byte 'F' - PRINT_FLAG xmm3 + mov [res_msg], byte 'F' + PRINT_FLAG xmm3 print_duhr: - mov [res_msg], byte 'D' - PRINT_FLAG xmm0 + mov [res_msg], byte 'D' + PRINT_FLAG xmm0 print_asr: - mov [res_msg], byte 'A' - PRINT_FLAG xmm4 + mov [res_msg], byte 'A' + PRINT_FLAG xmm4 print_maghrib: - mov [res_msg], byte 'M' - PRINT_FLAG xmm5 + mov [res_msg], byte 'M' + PRINT_FLAG xmm5 print_isha: - mov [res_msg], byte 'I' - PRINT_FLAG xmm7 + mov [res_msg], byte 'I' + PRINT_FLAG xmm7 print_unix: PRINT_INT xmm14 EEXIT EXIT_SUCCESS print_24: - subsd xmm14, xmm15 ;prayer timestamp - start_of_day - SEC_TO_HM xmm14 - PRINT_EXIT + subsd xmm14, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm14 + PRINT_HM + EEXIT EXIT_SUCCESS print_12: - subsd xmm14, xmm15 ;prayer timestamp - start_of_day - SEC_TO_HM xmm14 - cmp r8, 0xc - ja sub12h - PRINT_EXIT + subsd xmm14, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm14 + cmp r8, 0xc + ja sub12h + PRINT_HM + EEXIT EXIT_SUCCESS sub12h: sub r8, 0xc - PRINT_EXIT + PRINT_HM + EEXIT EXIT_SUCCESS print_all_u: PRINT_INT xmm3 ;fajr @@ -367,6 +385,32 @@ print_all_u: PRINT_INT xmm7 ;isha EEXIT EXIT_SUCCESS +print_all_24: + mov [res_msg], byte 'F' + subsd xmm3, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm3 + PRINT_HM + + mov [res_msg], byte 'D' + subsd xmm0, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm0 + PRINT_HM + + mov [res_msg], byte 'A' + subsd xmm4, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm4 + PRINT_HM + + mov [res_msg], byte 'M' + subsd xmm5, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm5 + PRINT_HM + + mov [res_msg], byte 'I' + subsd xmm7, xmm15 ;prayer timestamp - start_of_day + SEC_TO_HM xmm7 + PRINT_HM + ; result_hour ;r8 ; result_min ;r9 ; duhr_ts: ;xmm0 @@ -385,4 +429,4 @@ print_all_u: ; macros: ;xmm14 ; start_of_day: ;xmm15 - EEXIT EXIT_SUCCESS + EEXIT EXIT_SUCCESS diff --git a/macros.s b/macros.s index eaaf8ff..d2028a7 100644 --- a/macros.s +++ b/macros.s @@ -35,14 +35,13 @@ section .note.openbsd.ident note EEXIT EXIT_FAILURE %endmacro -%macro PRINT_EXIT 0 +%macro PRINT_HM 0 SET_MSG mov rax, SYS_write mov rdi, STDOUT mov rsi, res_msg mov rdx, res_len syscall - EEXIT EXIT_SUCCESS %endmacro %macro SEC_TO_HM 1 @@ -168,7 +167,8 @@ next_digit: je print_12 subsd %1, xmm6 ;print diff = prayer time - tstamp = %1 SEC_TO_HM %1 - PRINT_EXIT + PRINT_HM + EEXIT EXIT_SUCCESS %endmacro %endif ;MACROS_S -- 2.11.4.GIT