URL
                    https://opencores.org/ocsvn/forwardcom/forwardcom/trunk
                
            Subversion Repositories forwardcom
[/] [forwardcom/] [examples/] [integrate.as] - Rev 158
Go to most recent revision | Compare with Previous | Blame | View Log
/*************************** integrate.as ************************************ Author: Agner Fog* date created: 2018-02-30* Version: 1.00* Project: ForwardCom example, assembly code* Description: Numerical integration of sin(x) from 0 to pi/2** Link with libraries libc.li and math.li** Copyright 2018 GNU General Public License http://www.gnu.org/licenses*****************************************************************************/// define parameters. you may change these% npoints = 8 // number of function points to calculate. must be a power of 2% M_PI = 3.14159265358979323846 // pi% startvalue = 0 // start of x interval% endvalue = M_PI / 2 // end of x intervalconst section read ip // read-only data section// format string for printfform: int8 "\nNumerical integration of sin(x) from %f to %f "int8 "with %i function points."int8 "\nThe result is %.15f\n",0const endbss section datap uninitialized // uninitialized read/write data sectionint64 parlist[8] // parameter list for printfbss endcode section execute align = 4 // code sectionextern _sin: function // library function: sine in radiansextern _integrate: function // library function: numerical integrationextern _printf: function // library function: formatted output to stdout_main function public // program begins heredouble v0 = startvalue // x interval startdouble v1 = endvalue // x interval endint64 r0 = address([_sin]) // function pointerint64 r1 = npoints // number of x pointscall _integrate // integrate sin(x)// print resultsint64 r0 = address([form]) // format string for printfint64 r1 = address([parlist]) // parameter list for printfdouble v1 = startvalue // parametersdouble v2 = endvalueint32+ r2 = npointsdouble [r1, scalar] = v1 // put parameters into variable argument list for printfdouble [r1+8, scalar] = v2int64 [r1+16 ] = r2double [r1+24, scalar] = v0call _printf // print resultsint64 r0 = 0 // program return valuereturn // return from main_main endcode end
Go to most recent revision | Compare with Previous | Blame | View Log
