1 ; See LICENSE file for copyright
and license details.
2 ; azan-nasm is simple muslim prayers calculator.
3 ; print next prayer left duration
or today
's all prayers.
12 sec_inday: dq 0x40f5180000000000 ;double 86400.0
13 jul1970: dq 0x41429ec5c0000000 ;double 2440587.5
14 offset: dq 0xc142b42c80000000 ;double -2451545
15 to_rad: dq 0x3f91df46a2529d39 ;double pi / 180
16 to_deg: dq 0x404ca5dc1a63c1f8 ;double 180 / pi
17 g_1: dq 0x3fef8a099930e901 ;double 0.98560027999999999
18 g_2: dq 0x40765876c8b43958 ;double 357.529
19 e_3: dq 0xbe9828c0be769dc1 ;double -3.5999999999999999E-7
20 e_4: dq 0x403770624dd2f1aa ;double 23.439
21 q_5: dq 0x3fef8a6c5512d6f2 ;double 0.98564735999999997
22 q_6: dq 0x4071875810624dd3 ;double 280.459
23 sing_1: dq 0x3FFEA3D70A3D70A4 ;double 1.915
24 sing_2: dq 0x3F947AE147AE147B ;double 0.020
25 RA_1: dq 0x402E000000000000 ;double 15.0
26 eqt_1: dq 0x4076800000000000 ;double 360.0
27 duhr_1: dq 0x4028000000000000 ;double 12.0
28 pray_1: dq 0x4038000000000000 ;double 24.0
29 neg1: dq 0xBFF0000000000000 ;double -1.0
30 p1: dq 0X3fb1111111111111 ;double 0.066666666666666666
31 sec_inhour: dq 0x40ac200000000000 ;double 3600
32 sec_inmin: dq 0x404e000000000000 ;double 60
33 maghrib_1: dq 0x3fa1c432ca57a787 ;double 0.0347
34 maghrib_2: dq 0x3feaaaaaaaaaaaab ;double 0.833333333333333333
35 isha_nor: dq 0x40b5180000000000 ;double 5400.0 90 min
36 isha_ram: dq 0x40bc200000000000 ;double 7200.0 120 min
52 DIE usage_msg, usage_len
55 mov r11, [rsp+8] ;argv
56 cmp [r11], byte 0x2d ;-
58 cmp [r11+2], byte 0x00
65 DIE version_msg, version_len
68 mov rax, SYS_gettimeofday ;sys_gettimeofday(
69 mov rdi, tmp0 ;struct timeval *tv,
70 mov rsi, rsi ;struct timezone* tz
73 ;start_of_day = tstamp - (tstamp % 86400);
77 imul rax, rax, -1037155065
87 movsd xmm14, [time_zone]
88 mulsd xmm14, [sec_inhour]
91 ;tstamp = xmm6 convert tstamp to double
94 ;julian = tstamp / sec_inday) + jul1970 = xmm0
95 movsd xmm0, xmm6 ;copy tstamp to xmm0
96 divsd xmm0, [sec_inday] ;tstamp / sec_inday
97 addsd xmm0, [jul1970] ;div result + jul1970
99 calc_equation_of_time:
100 ;d = julian - offset = xmm0
103 ;g = to_rad * ((d * 0.98560028) + 357.529) = xmm1
109 ;e = to_rad * (23.439 - (d * 0.00000036)) = xmm3
115 ;q = (d * 0.98564736) + 280.459 = xmm4
120 ;sing = 1.915 * sin(g) = xmm5
125 ;sin2g = 0.020 * sin(2.0*g) = xmm1
138 ;L = to_rad(q + sing + sin2g) = xmm5
150 ;RA = to_deg(atan2(cose * sinL, cosL) / 15.0) = xmm7
151 mulsd xmm7, xmm2 ;cose * sinL
152 ATAN2 xmm7, xmm5 ;result in xmm7
153 divsd xmm7, [RA_1] ;atan2 result /15.0
154 mulsd xmm7, [to_deg] ;* to_deg
156 ;D = to_deg(asin(sine * sinL)) = xmm8
161 ;EqT = q / 15.0 - RA = xmm9
162 movsd xmm9, xmm4 ;move q to xmm9
163 divsd xmm9, [RA_1] ;q / 15.0
164 subsd xmm9, xmm7 ;- RA
165 subsd xmm9, [eqt_1] ;EqT = EqT - 360.0
167 get_duhr: ;duhr = 12.0+time_zone-EqT-(longitude/15.0)=xmm0
168 movsd xmm1, [longitude]
171 addsd xmm0, [time_zone]
180 get_fajr: ;fajr = duhr - T(fajr_angle, D) = xmm3
182 movsd xmm3, [fajr_angle]
185 ;fajr = duhr - T = xmm3
191 mulsd xmm3, [sec_inhour] ;convert to seconds
192 roundsd xmm3, xmm3, ROUND_DOWN
193 addsd xmm3, xmm15 ;fajr seconds + start_of_day
194 ucomisd xmm3, xmm6 ;if fajr > tstamp
198 movsd xmm13, xmm0 ;save duhr to xmm13
199 mulsd xmm0, [sec_inhour] ;convert to seconds
200 roundsd xmm0, xmm0, ROUND_DOWN
201 addsd xmm0, xmm15 ;duhr seconds + start_of_day
202 ucomisd xmm0, xmm6 ;if duhr > tstamp
205 get_asr: ;asr = duhr + A(1.0, D);
207 ;p4 = tan(convert_degrees_to_radians((latitude - D)))
208 ;p5 = atan2(1.0, (t + p4));
210 movsd xmm4, [latitude]
223 ;p7 = convert_radians_to_degrees(acos((p6 - p3) / p2));
235 mulsd xmm4, [sec_inhour] ;convert to seconds
236 roundsd xmm4, xmm4, ROUND_DOWN
237 addsd xmm4, xmm15 ;asr seconds + start_of_day
238 ucomisd xmm4, xmm6 ;if asr > tstamp
241 get_maghrib: ;duhr + T(0.8333 + 0.0347 * sqrt(altitude), D) = xmm5
242 sqrtsd xmm5, [altitude]
243 mulsd xmm5, [maghrib_1]
244 addsd xmm5, [maghrib_2]
249 mulsd xmm5, [sec_inhour] ;convert to seconds
250 roundsd xmm5, xmm5, ROUND_DOWN
251 addsd xmm5, xmm15 ;maghrib seconds + start_of_day
252 ucomisd xmm5, xmm6 ;if maghrib > tstamp
257 cmp rcx, use_umm_al_qura
262 um_nor: ;maghrib + 90.0 min;
263 movsd xmm7, [isha_nor]
267 um_ram: ;maghrib + 120.0 min;
268 movsd xmm7, [isha_ram]
272 calc_isha_nor: ;duhr + T(isha_angle, D);
273 movsd xmm7, [isha_angle]
279 ucomisd xmm7, xmm6 ;if isha > tstamp
282 get_nfajr: ;fajr + sec_inday
283 movsd xmm12, [sec_inday]
287 mov [res_msg], byte 'F
'
295 mov [res_msg], byte 'F
'
303 mov [res_msg], byte 'D
'
311 mov [res_msg], byte 'A'
319 mov [res_msg], byte 'M
'
327 mov [res_msg], byte 'I
'
335 PRINT_INT ;from xmm14
352 ; start_of_day: ;xmm15