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.
13 sec_inday: dq 0x40f5180000000000 ;double 86400.0
14 jul1970: dq 0x41429ec5c0000000 ;double 2440587.5
15 offset: dq 0xc142b42c80000000 ;double -2451545
16 to_rad: dq 0x3f91df46a2529d39 ;double pi / 180
17 to_deg: dq 0x404ca5dc1a63c1f8 ;double 180 / pi
18 g_1: dq 0x3fef8a099930e901 ;double 0.98560027999999999
19 g_2: dq 0x40765876c8b43958 ;double 357.529
20 e_3: dq 0xbe9828c0be769dc1 ;double -3.5999999999999999E-7
21 e_4: dq 0x403770624dd2f1aa ;double 23.439
22 q_5: dq 0x3fef8a6c5512d6f2 ;double 0.98564735999999997
23 q_6: dq 0x4071875810624dd3 ;double 280.459
24 sing_1: dq 0x3FFEA3D70A3D70A4 ;double 1.915
25 sing_2: dq 0x3F947AE147AE147B ;double 0.020
26 RA_1: dq 0x402E000000000000 ;double 15.0
27 eqt_1: dq 0x4076800000000000 ;double 360.0
28 duhr_1: dq 0x4028000000000000 ;double 12.0
29 pray_1: dq 0x4038000000000000 ;double 24.0
30 neg1: dq 0xBFF0000000000000 ;double -1.0
31 p1: dq 0X3fb1111111111111 ;double 0.066666666666666666
32 sec_inhour: dq 0x40ac200000000000 ;double 3600
33 sec_inmin: dq 0x404e000000000000 ;double 60
34 maghrib_1: dq 0x3fa1c432ca57a787 ;double 0.0347
35 maghrib_2: dq 0x3feaaaaaaaaaaaab ;double 0.833333333333333333
36 isha_nor: dq 0x40b5180000000000 ;double 5400.0 90 min
37 isha_ram: dq 0x40bc200000000000 ;double 7200.0 120 min
53 DIE usage_msg, usage_len
56 mov r11, [rsp+8] ;argv
57 cmp [r11], byte 0x2d ;-
59 cmp [r11+2], byte 0x00
68 DIE version_msg, version_len
71 mov rax, SYS_gettimeofday ;sys_gettimeofday(
72 mov rdi, tmp0 ;struct timeval *tv,
73 mov rsi, rsi ;struct timezone* tz
76 ;start_of_day = tstamp - (tstamp % 86400);
80 imul rax, rax, -1037155065
90 movsd xmm14, [time_zone]
91 mulsd xmm14, [sec_inhour]
94 ;tstamp = xmm6 convert tstamp to double
97 ;julian = tstamp / sec_inday) + jul1970 = xmm0
98 movsd xmm0, xmm6 ;copy tstamp to xmm0
99 divsd xmm0, [sec_inday] ;tstamp / sec_inday
100 addsd xmm0, [jul1970] ;div result + jul1970
102 calc_equation_of_time:
103 ;d = julian - offset = xmm0
106 ;g = to_rad * ((d * 0.98560028) + 357.529) = xmm1
112 ;e = to_rad * (23.439 - (d * 0.00000036)) = xmm3
118 ;q = (d * 0.98564736) + 280.459 = xmm4
123 ;sing = 1.915 * sin(g) = xmm5
128 ;sin2g = 0.020 * sin(2.0*g) = xmm1
141 ;L = to_rad(q + sing + sin2g) = xmm5
153 ;RA = to_deg(atan2(cose * sinL, cosL) / 15.0) = xmm7
154 mulsd xmm7, xmm2 ;cose * sinL
155 ATAN2 xmm7, xmm5 ;result in xmm7
156 divsd xmm7, [RA_1] ;atan2 result /15.0
157 mulsd xmm7, [to_deg] ;* to_deg
159 ;D = to_deg(asin(sine * sinL)) = xmm8
164 ;EqT = q / 15.0 - RA = xmm9
165 movsd xmm9, xmm4 ;move q to xmm9
166 divsd xmm9, [RA_1] ;q / 15.0
167 subsd xmm9, xmm7 ;- RA
168 subsd xmm9, [eqt_1] ;EqT = EqT - 360.0
170 get_duhr: ;duhr = 12.0+time_zone-EqT-(longitude/15.0)=xmm0
171 movsd xmm1, [longitude]
174 addsd xmm0, [time_zone]
183 get_fajr: ;fajr = duhr - T(fajr_angle, D) = xmm3
185 movsd xmm3, [fajr_angle]
188 ;fajr = duhr - T = xmm3
194 mulsd xmm3, [sec_inhour] ;convert to seconds
195 roundsd xmm3, xmm3, ROUND_DOWN
196 addsd xmm3, xmm15 ;fajr seconds + start_of_day
197 ucomisd xmm3, xmm6 ;if fajr > tstamp
201 movsd xmm13, xmm0 ;save duhr to xmm13
202 mulsd xmm0, [sec_inhour] ;convert to seconds
203 roundsd xmm0, xmm0, ROUND_DOWN
204 addsd xmm0, xmm15 ;duhr seconds + start_of_day
205 ucomisd xmm0, xmm6 ;if duhr > tstamp
208 get_asr: ;asr = duhr + A(1.0, D);
210 ;p4 = tan(convert_degrees_to_radians((latitude - D)))
211 ;p5 = atan2(1.0, (t + p4));
213 movsd xmm4, [latitude]
226 ;p7 = convert_radians_to_degrees(acos((p6 - p3) / p2));
238 mulsd xmm4, [sec_inhour] ;convert to seconds
239 roundsd xmm4, xmm4, ROUND_DOWN
240 addsd xmm4, xmm15 ;asr seconds + start_of_day
241 ucomisd xmm4, xmm6 ;if asr > tstamp
244 get_maghrib: ;duhr + T(0.8333 + 0.0347 * sqrt(altitude), D) = xmm5
245 sqrtsd xmm5, [altitude]
246 mulsd xmm5, [maghrib_1]
247 addsd xmm5, [maghrib_2]
252 mulsd xmm5, [sec_inhour] ;convert to seconds
253 roundsd xmm5, xmm5, ROUND_DOWN
254 addsd xmm5, xmm15 ;maghrib seconds + start_of_day
255 ucomisd xmm5, xmm6 ;if maghrib > tstamp
260 cmp rcx, use_umm_al_qura
265 um_nor: ;maghrib + 90.0 min;
266 movsd xmm7, [isha_nor]
270 um_ram: ;maghrib + 120.0 min;
271 movsd xmm7, [isha_ram]
275 calc_isha_nor: ;duhr + T(isha_angle, D);
276 movsd xmm7, [isha_angle]
282 ucomisd xmm7, xmm6 ;if isha > tstamp
285 get_nfajr: ;fajr + sec_inday
286 movsd xmm12, [sec_inday]
290 mov [res_msg], byte 'F
'
295 subsd xmm12, xmm6 ;diff = prayer time - tstamp = xmm12
300 mov [res_msg], byte 'F
'
304 subsd xmm3, xmm6 ;diff = prayer time - tstamp = xmm3
309 mov [res_msg], byte 'D
'
315 subsd xmm0, xmm6 ;diff = prayer time - tstamp = xmm0
320 mov [res_msg], byte 'A'
326 subsd xmm4, xmm6 ;diff = prayer time - tstamp = xmm4
331 mov [res_msg], byte 'M
'
337 subsd xmm5, xmm6 ;diff = prayer time - tstamp = xmm5
342 mov [res_msg], byte 'I
'
348 subsd xmm7, xmm6 ;diff = prayer time - tstamp = xmm7
353 PRINT_INT ;from xmm14
356 subsd xmm14, xmm15 ;prayer timestamp - start_of_day
376 ; start_of_day: ;xmm15