-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtrigonometric-f.as
More file actions
58 lines (48 loc) · 2.56 KB
/
trigonometric-f.as
File metadata and controls
58 lines (48 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/************************* trigonometric-f.as ********************************
* Author: Agner Fog
* date created: 2018-02-29
* last modified: 2024-08-11
* Version: 1.13
* Project: ForwardCom example, assembly code
* Description: Makes a table of sine, cosine, and tangent
* Uses a simple loop without vectorization
*
* Link with libraries libc.li and math.li
*
* Copyright 2018-2024 GNU General Public License www.gnu.org/licenses
*****************************************************************************/
const section read ip // read-only data section
intro: int8 "\n x sin(x) cos(x) tan(x)",0 // table heading
form: int8 "\n%6.3f %12.8f %12.8f %12.8f",0 // format string for printf
newline: int8 "\n",0 // newline
const end
bss section datap uninitialized // uninitialized read/write data section
int64 parlist[5] // parameter list for printf
bss end
code section execute align = 4 // code section
extern _sincosf: function, reguse = 0, 0x7BF // library function: sine and cosine in radians
extern _printf: function // library function: formatted output to stdout
extern _puts: function // library function: print string to stdout
_main function public // program begins here
int64 r0 = address([intro])
call _puts // write introduction text
for (double v12 = -1; v12 < 4; v12 += 0.1) { // loop
float v0 = compress(v12, 0)
call _sincosf // sin(x) in v0, cos(x) in v1
double v0 = expand(v0, 0)
double v1 = expand(v1, 0)
double v2 = v0 / v1 // tan(x) = sin(x) / cos(x)
int64 r0 = address([form]) // format string
int64 r1 = address([parlist]) // parameter list for _printf
double [parlist, scalar] = v12 // x
double [parlist+8, scalar] = v0 // sin(x)
double [parlist+16, scalar] = v1 // cos(x)
double [parlist+24, scalar] = v2 // tan(x)
call _printf // print formatted results
}
int64 r0 = address([newline]) // end with newline
call _puts
int64 r0 = 0 // program return value
return // return from main
_main end
code end