OpenCores
URL https://opencores.org/ocsvn/forwardcom/forwardcom/trunk

Subversion Repositories forwardcom

[/] [forwardcom/] [examples/] [trigonometric-f.as] - Blame information for rev 131

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.