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

Subversion Repositories forwardcom

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 130 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 _sincos: 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 = v12                               // x
38
   call _sincos                                  // sin(x) in v0, cos(x) in v1
39
   double v2 = v0 / v1                           // tan(x) = sin(x) / cos(x)
40
   int64 r0 = address([form])                    // format string
41
   int64 r1 = address([parlist])                 // parameter list for _printf
42
   double [parlist,    scalar] = v12             // x
43
   double [parlist+8,  scalar] = v0              // sin(x)
44
   double [parlist+16, scalar] = v1              // cos(x)
45
   double [parlist+24, scalar] = v2              // tan(x)
46
   call _printf                                  // print formatted results
47
}
48
 
49
int64 r0 = address([newline])                    // end with newline
50
call _puts
51
 
52
int64 r0 = 0                                     // program return value
53
return                                           // return from main
54
_main end
55
 
56
code end

powered by: WebSVN 2.1.0

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