From 9ddea720055aba55b30a661e99fd344fbfcaa387 Mon Sep 17 00:00:00 2001 From: afify Date: Fri, 6 Nov 2020 14:03:54 +0300 Subject: [PATCH] [feat] print julian, create util.s - use timestamp to julian: return ( unixsecs / 86400.0 ) + 2440587.5; - move _printRAX to util.s --- Makefile | 2 +- azan-nasm.s | 108 +++++++++++++++++++------------------------------- config.mk | 2 +- azan-nasm.s => util.s | 22 +--------- 4 files changed, 44 insertions(+), 90 deletions(-) rewrite azan-nasm.s (69%) copy azan-nasm.s => util.s (61%) diff --git a/Makefile b/Makefile index 5b40bcb..9fd722c 100644 --- 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 dissimilarity index 69% index 3001a9f..c4b0d6b 100644 --- a/azan-nasm.s +++ b/azan-nasm.s @@ -1,68 +1,40 @@ -; See LICENSE file for copyright and license details. -; azan-nasm is simple muslim prayers calculator. -; print next prayer left duration or today's all prayers. - -BITS 64 -%include "syscalls.s" -%include "macros.s" -CHECK_OPENBSD - -section .bss - digitSpace: resb 100 - digitSpacePos: resb 8 - current_time: resb 12 - -section .text - global _start - -_start: - mov rax, SYS_gettimeofday - mov rdi, current_time - mov rsi, rsi - syscall - - mov rax, [current_time] - - call _printRAX - 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 +; See LICENSE file for copyright and license details. +; azan-nasm is simple muslim prayers calculator. +; print next prayer left duration or today's all prayers. + +BITS 64 +%include "syscalls.s" +%include "macros.s" +CHECK_OPENBSD + +section .bss + 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: +; 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 diff --git a/config.mk b/config.mk index 301e364..f5ed4ce 100644 --- 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/azan-nasm.s b/util.s similarity index 61% copy from azan-nasm.s copy to util.s index 3001a9f..a65c6be 100644 --- a/azan-nasm.s +++ b/util.s @@ -1,30 +1,12 @@ -; See LICENSE file for copyright and license details. -; azan-nasm is simple muslim prayers calculator. -; print next prayer left duration or today's all prayers. - BITS 64 %include "syscalls.s" -%include "macros.s" -CHECK_OPENBSD - +%idefine rip rel $ section .bss digitSpace: resb 100 digitSpacePos: resb 8 - current_time: resb 12 section .text - global _start - -_start: - mov rax, SYS_gettimeofday - mov rdi, current_time - mov rsi, rsi - syscall - - mov rax, [current_time] - - call _printRAX - EEXIT EXIT_SUCCESS + global _printRAX _printRAX: mov rcx, digitSpace -- 2.11.4.GIT