commit 168ed1a2e9279fe45a8976d6cca8e5d7ba7b80fa
parent 55c382f4b11b9ba091d32aa56cb8b4683c64f292
Author: afify <hassan@afify.dev>
Date: Wed, 18 Nov 2020 18:05:31 +0300
[feat] handel command arg
- if argc > 2 die_usage
- if argc == 2 die_version
if argv[1] == -v\0 print version
else die_usage
- else continue
- create functions: die_usage and die_version
- set MAX_ARGC
- set die messages
- create DIE macro
- define VERSION
Diffstat:
3 files changed, 28 insertions(+), 51 deletions(-)
diff --git a/azan-nasm.s b/azan-nasm.s
@@ -52,6 +52,24 @@ section .text
global _start
_start:
+ pop rcx
+ cmp rcx, MAX_ARGC
+ jl get_timestamp
+ je die_version
+
+die_usage:
+ DIE usage_msg, usage_len
+
+die_version:
+ mov rcx, [rsp+8] ; argv
+ cmp [rcx], byte '-'
+ jne die_usage
+ cmp [rcx+1], byte 'v'
+ jne die_usage
+ cmp [rcx+2], byte 0
+ jne die_usage
+ DIE version_msg, version_len
+
get_timestamp:
mov rax, SYS_gettimeofday ;sys_gettimeofday(
mov rdi, tstamp ;struct timeval *tv,
diff --git a/config.mk b/config.mk
@@ -1,16 +1,14 @@
# azan-nasm version
VERSION = 0.1
-# Customize below to fit your system
-
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
# flags
-AFLAGS = -f elf64 -w+all -D$$(uname)
+AFLAGS = -f elf64 -w+all -D$$(uname) -DVERSION=\"${VERSION}\"
LFLAGS = -m elf_x86_64 -s -no-pie
-# compiler and linker
+# assembler and linker
ASM = nasm
LNK = ld
diff --git a/macros.s b/macros.s
@@ -9,14 +9,13 @@
%define STDERR 2
%define ROUND_UP 10B ;toward +inf
%define ROUND_DOWN 01B ;toward -inf
+%define MAX_ARGC 2
section .rodata
- failure_msg: db 0x5b, 0x1b, 0x5b, 0x33, 0x31, 0x6d, 0x46\
- 0x41, 0x49, 0x4c, 0x45, 0x44, 0x1b, 0x5b\
- 0x30, 0x6d, 0x5d, 0x20, 0x00
- failure_msglen: equ $ - failure_msg
- julian_msg: db "Julian must be greader than offset.", 10, 0
- julian_msglen: equ $ - julian_msg
+ usage_msg: db "usage: azan-nasm [-v]", 10, 0
+ usage_len: equ $ - usage_msg
+ version_msg: db "azan-nasm-", VERSION, 10, 0
+ version_len: equ $ - version_msg
%macro CHECK_OPENBSD 0
%ifdef OpenBSD
@@ -33,53 +32,15 @@ section .note.openbsd.ident note
syscall
%endmacro
-%macro FAIL_MSG 0
+%macro DIE 2
mov rax, SYS_write
mov rdi, STDERR
- mov rsi, failure_msg
- mov rdx, failure_msglen
- syscall
-%endmacro
-
-%macro FAILJULIAN 0
- FAIL_MSG
- mov rax, SYS_write
- mov rdi, STDERR
- mov rsi, julian_msg
- mov rdx, julian_msglen
+ mov rsi, %1
+ mov rdx, %2
syscall
EEXIT EXIT_FAILURE
%endmacro
-; %macro ACOS 1; acos(x) = atan(sqrt((1-x*x)/(x*x)))
-; fld qword %1
-; fld st0
-; fmul
-; fld st0
-; fld1
-; fsubr
-; fdivr
-; fsqrt
-; fld1
-; fpatan
-; fstp qword %1
-; %endmacro
-
-; %macro ASIN 1 ;asin(x) = atan(sqrt(x*x/(1-x*x)))
-; fld qword %1
-; fld st0
-; fmul
-; fld st0
-; fld1
-; fsubr
-; fdiv
-; fsqrt
-; fld1
-; fpatan
-; fstp qword %1
-; %endmacro
-
-
%macro ACOS 1; acos(x) = atan(sqrt((1-x*x)/(x*x)))
fld qword %1
fld st0