azan

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

commit 9ddea720055aba55b30a661e99fd344fbfcaa387
parent 333f337f86be12ea2b88becf6cc0c09185b59591
Author: afify <hassan@afify.dev>
Date:   Fri,  6 Nov 2020 14:03:54 +0300

[feat] print julian, create util.s

- use timestamp to julian:
	return ( unixsecs / 86400.0 ) + 2440587.5;
- move _printRAX to util.s

Diffstat:
MMakefile | 2+-
Mazan-nasm.s | 76++++++++++++++++++++++++----------------------------------------------------
Mconfig.mk | 2+-
Autil.s | 50++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 76 insertions(+), 54 deletions(-)

diff --git a/Makefile b/Makefile @@ -4,7 +4,7 @@ include config.mk BIN = azan-nasm -SRC = ${BIN}.s +SRC = ${BIN}.s util.s OBJ = ${SRC:.s=.o} all: options ${BIN} diff --git a/azan-nasm.s b/azan-nasm.s @@ -8,61 +8,33 @@ BITS 64 CHECK_OPENBSD section .bss - digitSpace: resb 100 - digitSpacePos: resb 8 - current_time: resb 12 + timestamp: resb 12 + julian: resb 12 + equation_of_time: resb 12 + res_char: resb 1 + res_hour: resb 2 + res_min: resb 2 +section .rodata + julian_1970: dq 0x41429ec5c0000000 ; double 2440587.5 + sec_in_day: dq 0x40f5180000000000 ; double 86400 section .text global _start + extern _printRAX _start: - mov rax, SYS_gettimeofday - mov rdi, current_time - mov rsi, rsi - syscall - - mov rax, [current_time] - - call _printRAX +; get_timestamp: + mov rax, SYS_gettimeofday ;sys_gettimeofday( + mov rdi, timestamp ;struct timeval *tv, + mov rsi, rsi ;struct timezone* tz + syscall ;) + +; calc_julian: + mov rax, [timestamp] ; mov value of timestamp in rax + mov rbx, sec_in_day ; rbx = SEC_IN_DAY + div rbx ; timestamp / SEC_IN_DAY + add rax, 2440587 + mov [julian], rax ; save result of division in julian + + call _printRAX ;util.s EEXIT EXIT_SUCCESS - -_printRAX: - mov rcx, digitSpace - mov rbx, 10 - mov [rcx], rbx - inc rcx - mov [digitSpacePos], rcx - -_printRAXLoop: - mov rdx, 0 - mov rbx, 10 - div rbx - push rax - add rdx, 48 - - mov rcx, [digitSpacePos] - mov [rcx], dl - inc rcx - mov [digitSpacePos], rcx - - pop rax - cmp rax, 0 - jne _printRAXLoop - -_printRAXLoop2: - mov rcx, [digitSpacePos] - - mov rax, SYS_write - mov rdi, 1 - mov rsi, rcx - mov rdx, 1 - syscall - - mov rcx, [digitSpacePos] - dec rcx - mov [digitSpacePos], rcx - - cmp rcx, digitSpace - jge _printRAXLoop2 - - ret diff --git a/config.mk b/config.mk @@ -9,7 +9,7 @@ MANPREFIX = ${PREFIX}/share/man # flags AFLAGS = -f elf64 -w+all -D$$(uname) -LFLAGS = -m elf_x86_64 -no-pie +LFLAGS = -m elf_x86_64 -s -no-pie # compiler and linker ASM = nasm diff --git a/util.s b/util.s @@ -0,0 +1,50 @@ +BITS 64 +%include "syscalls.s" +%idefine rip rel $ +section .bss + digitSpace: resb 100 + digitSpacePos: resb 8 + +section .text + global _printRAX + +_printRAX: + mov rcx, digitSpace + mov rbx, 10 + mov [rcx], rbx + inc rcx + mov [digitSpacePos], rcx + +_printRAXLoop: + mov rdx, 0 + mov rbx, 10 + div rbx + push rax + add rdx, 48 + + mov rcx, [digitSpacePos] + mov [rcx], dl + inc rcx + mov [digitSpacePos], rcx + + pop rax + cmp rax, 0 + jne _printRAXLoop + +_printRAXLoop2: + mov rcx, [digitSpacePos] + + mov rax, SYS_write + mov rdi, 1 + mov rsi, rcx + mov rdx, 1 + syscall + + mov rcx, [digitSpacePos] + dec rcx + mov [digitSpacePos], rcx + + cmp rcx, digitSpace + jge _printRAXLoop2 + + ret