Horizontal sundial calculations: Difference between revisions

Line 502:
HR= +6; HRA= +90.500; HLA= +84.225
</pre>
 
=={{header|x86 Assembly}}==
{{works with|nasm}}
 
{{libheader|libc}}
 
It must be linked with the C standard library and startup code.
 
<lang asm>
global main
extern printf, scanf
 
section .text
 
getvalue:
push edx
push eax
call printf
add esp, 4
push in_ft
call scanf
add esp, 8
ret
 
st0dr:
fld qword [drfact]
fmul
ret
 
main:
lea eax, [lat_t]
lea edx, [lat]
call getvalue
lea eax, [lng_t]
lea edx, [lng]
call getvalue
lea eax, [ref_t]
lea edx, [ref]
call getvalue
 
push newline
call printf
add esp, 4
 
fld qword [lat]
call st0dr
fsin
fst qword [slat]
 
sub esp, 8
fstp qword [esp]
push sin_ft
call printf
add esp, 12
 
fld qword [lng]
fld qword [ref]
fsubr st0, st1
sub esp, 8
fstp qword [esp]
push diff_ft
call printf
add esp, 12
 
push tab_t
call printf
add esp, 4
 
mov ecx, -6
.loop:
cmp ecx, 6
jg .endloop
 
push ecx
fild dword [esp]
fld qword [xv]
fmulp
fld qword [lng]
fsubp
fld qword [ref]
faddp
pop ecx
 
sub esp, 20
mov dword [esp], ecx
fst qword [esp+4]
call st0dr
 
fptan
fxch
fld qword [slat]
fmulp
fxch
fpatan
 
fld qword [rdinv]
fmul
fstp qword [esp+12]
push o_ft
call printf
mov ecx, [esp+4]
add esp, 24
 
inc ecx
jmp .loop
.endloop:
xor eax, eax
ret
 
section .data
lat: dq 0.0
lng: dq 0.0
ref: dq 0.0
xv: dq 15.0
slat: dq 0.0
drfact: dq 0.01745329251994329576
rdinv: dq 57.29577951308232090712
 
 
section .rodata
 
lat_t: db "Enter latitude: ", 0
lng_t: db "Enter longitude: ", 0
ref_t: db "Enter legal meridian: ", 0
 
in_ft: db "%lf", 0
newline:
db 10, 0
 
sin_ft:
db "sine of latitude: %.3f", 10, 0
diff_ft:
db "diff longitude: %.3f", 10, 10, 0
 
tab_t:
db "Hour, sun hour angle, dial hour line angle from 6am to 6pm", 10, 0
 
o_ft:
db "HR= %3d; ",9," HRA=%7.3f; ",9," HLA= %7.3f", 10, 0</lang>