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

Subversion Repositories forwardcom

[/] [forwardcom/] [examples/] [integrate.as] - Blame information for rev 128

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 128 Agner
/***************************  integrate.as  ***********************************
2
* Author:        Agner Fog
3
* date created:  2018-02-30
4
* Version:       1.00
5
* Project:       ForwardCom example, assembly code
6
* Description:   Numerical integration of sin(x) from 0 to pi/2
7
*
8
* Link with libraries libc.li and math.li
9
*
10
* Copyright 2018 GNU General Public License http://www.gnu.org/licenses
11
*****************************************************************************/
12
 
13
// define parameters. you may change these
14
% npoints = 8                          // number of function points to calculate. must be a power of 2
15
% M_PI = 3.14159265358979323846        // pi
16
% startvalue = 0                       // start of x interval
17
% endvalue = M_PI / 2                  // end of x interval
18
 
19
 
20
 
21
const section read ip                  // read-only data section
22
// format string for printf
23
form: int8 "\nNumerical integration of sin(x) from %f to %f "
24
      int8 "with %i function points."
25
      int8 "\nThe result is %.15f\n",0
26
const end
27
 
28
bss section datap uninitialized        // uninitialized read/write data section
29
int64 parlist[8]                       // parameter list for printf
30
bss end
31
 
32
code section execute align = 4         // code section
33
 
34
extern _sin: function                  // library function: sine in radians
35
extern _integrate: function            // library function: numerical integration
36
extern _printf: function               // library function: formatted output to stdout
37
 
38
_main function public                  // program begins here
39
 
40
double v0 = startvalue                 // x interval start
41
double v1 = endvalue                   // x interval end
42
int64  r0 = address([_sin])            // function pointer
43
int64  r1 = npoints                    // number of x points
44
call _integrate                        // integrate sin(x)
45
 
46
// print results
47
int64  r0 = address([form])            // format string for printf
48
int64  r1 = address([parlist])         // parameter list for printf
49
double v1 = startvalue                 // parameters
50
double v2 = endvalue
51
int32+ r2 = npoints
52
double [r1,    scalar] = v1            // put parameters into variable argument list for printf
53
double [r1+8,  scalar] = v2
54
int64  [r1+16        ] = r2
55
double [r1+24, scalar] = v0
56
call _printf                           // print results
57
 
58
int64 r0 = 0                           // program return value
59
return                                 // return from main
60
_main end
61
 
62
code end

powered by: WebSVN 2.1.0

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