#define TRUE 1 #define FALSE 0 #define SIZE 18 #define STM_BASE 0x54000000 int abcd, channel; #define STP_TRACE_D8(_channel_,_data_) {*((volatile unsigned char *) (STM_BASE + 0x1000 * _channel_)) = _data_;} #define STP_TRACE_D8TS(_channel_,_data_) {*((volatile unsigned char *) (STM_BASE + 0x800 + 0x1000 * _channel_)) = _data_;} #define STP_TRACE_D16(_channel_,_data_) {*((volatile unsigned short *) (STM_BASE + 0x1000 * _channel_)) = _data_;} #define STP_TRACE_D16TS(_channel_,_data_) {*((volatile unsigned short *) (STM_BASE + 0x800 + 0x1000 * _channel_)) = _data_;} #define STP_TRACE_D32(_channel_,_data_) {*((volatile unsigned int *) (STM_BASE + 0x1000 * _channel_)) = _data_;} #define STP_TRACE_D32TS(_channel_,_data_) {*((volatile unsigned int *) (STM_BASE + 0x800 + 0x1000 * _channel_)) = _data_;} static int mstatic1; float vfloat = 1.0; double vdouble = 1.0; typedef int tdef1; tdef1 vtdef1; typedef short tdef2[10]; tdef2 vtdef2; struct { int x, y; } vstruct1; char vchar; short vshort; int vint; long vlong; char * vpchar; short * vpshort; int * vpint; long * vplong; unsigned char vuchar; unsigned short vushort; unsigned int vuint; unsigned long vulong; unsigned char * vpuchar; unsigned short * vpushort; unsigned int * vpuint; unsigned long * vpulong; unsigned char * * vppuchar; unsigned short * * vppushort; unsigned int * * vppuint; unsigned long * * vppulong; unsigned long * * * vpppulong; unsigned long * * * * vppppulong; int varray[10]; typedef int tarray[10]; tarray vtarray; char vdarray[5]; char vdiarray[] = "abcd"; char vdblarray[5][6]; char vtripplearray[2][2][2]; struct struct4 { struct struct5 * pstruct5; struct struct5 * * ppstruct5; struct struct5 * pastruct5[2]; } ; struct struct5 { struct struct4 * pstruct4; struct struct4 * * ppstruct4; struct struct4 * pastruct4[2]; } ; typedef struct struct1 { char * word; int count; struct struct1 * left; struct struct1 * right; int field1:2; unsigned field2:3; } strtype1 ; strtype1 ast; typedef struct struct1 structarray[10]; structarray stra1; struct struct4 stra2[5][5]; struct union1 { char * word; int count; struct struct1 * left; struct struct1 * right; union { int ival; float fval; char * pval; } uval; int field1:2; unsigned field2:3; } aun; struct struct2 { char * word; int count; char name[10]; } str2; struct struct6 { int x; struct struct7 { char * word; int count; } vstruct7; int y; } str6; struct abc { int x; int y; }; struct abc def; union tunion { int z1; short z2; char z3; struct abc z4; } vunion; enum enumtyp { enum1, enum2, enum4=4, enum7=7, enum8, enumx= -1 } enumvar; int ( *funcptr ) (); func0() /* empty function */ { } static void func1( intptr ) /* static function */ int * intptr; { (*intptr)++; } void func2() { int autovar; register int regvar; static int fstatic = 44; /* initialized static variable */ static int fstatic2; /* not initialized static variable */ autovar = regvar = fstatic; autovar++; func1( &autovar ); /* to force autovar as stack-scope */ func1( &fstatic ); /* to force fstatic as static-scope */ for ( regvar = 0; regvar < 5 ; regvar++ ) mstatic1 += regvar*autovar; fstatic += mstatic1; fstatic2 = 2*fstatic; func1( &fstatic2 ); STP_TRACE_D32(0, ((unsigned int) &func2) ); STP_TRACE_D32(1, (unsigned int) &fstatic2 ); STP_TRACE_D32(2, fstatic2 ); } static int func3() /* simple function */ { return 5; } struct struct1 func4( str ) /* function returning struct */ struct struct1 str; { str.count++; return str; } int func5( a, b, c ) /* multiple arguments */ int a; char b; long c; { return a+b*c; } float func6( a, b ) float a; float b; { vfloat = 1.0; vfloat = -1.0; vfloat = 10.0; vfloat = 1.6; return a*b; } double func7( a, b ) double a; double b; { vdouble = 1.0; vdouble = -1.0; vdouble = 10.0; vdouble = 1.6; return a*b; } struct bfield { int a:1; int b:2; int c:3; int d:7; int e:8; int f:15; int g:1; int h:15; int i:1; int j:16; unsigned k:1; unsigned l:2; unsigned m:16; }; struct bfield vbfield; static int * func9() /* nested local variables */ { static stat1 = 0; register reg1; auto auto1; auto1 = stat1; for ( reg1 = 0 ; reg1 < 2 ; reg1++ ) { static stat2 = 0; register reg2; auto auto2; auto2 = stat2; for ( reg2 = 0 ; reg2 < reg1 ; reg2++ ) { func1( &stat1 ); func1( &auto1 ); func1( &stat2 ); func1( &auto2 ); } } return &stat1; } int func11( x ) /* multiple returns */ int x; { static int t; t = x; STP_TRACE_D32(0, (unsigned int) &func11); STP_TRACE_D32(1, (unsigned int) &t); STP_TRACE_D32(2, (unsigned int) t); switch ( x ) { case 1: x = x+1; x = x*2; return x*x; case 2: return x+x; case 3: return x-x; case 4: x = x+1; x = x*2; return x*x; case 5: break; case 6: return x+x; default: break; } return x; } int func13( a, c, e ) /* arguments and locals stack-tracking */ int a, c, e; { int b, d, f; b = a+c+e; f = b+a; d = f*b; if ( e > 0 ) c += func13( b, f, e-1 ); return c+e+d; } int func14( x1 ) /* Parameter: 1 Byte */ char x1; { return 2*x1; } int func15( x1 ) /* Parameter: 1 Word */ short x1; { return 2*x1; } int func16( x1 ) /* Parameter: 1 Long */ long x1; { return (int) (2*x1); } int func17( x1, x2 ) /* Parameter: 2 Short */ short x1, x2; { return x1*x2; } int func18( x1, x2 ) /* Parameter: Short,Long */ short x1; long x2; { return x1*x2; } int func19( x1, x2 ) /* Parameter: Long,Short */ long x1; short x2; { return x1*x2; } int func20( x1, x2, x3 ) /* Parameter: 3 Short */ short x1, x2, x3; { return x1*x2*x3; } int func21( x1, x2, x3 ) /* Parameter: Long,Short,Short */ long x1; short x2, x3; { return x1*x2*x3; } int func22( x1, x2, x3 ) /* Parameter: Short,Long,Short */ short x1; long x2; short x3; { return x1*x2*x3; } int func23( x1, x2, x3 ) /* Parameter: Short,Short,Long */ short x1, x2; long x3; { return x1*x2*x3; } char func24() /* Char Return */ { return 55; } long func25() /* Long Return */ { return 12345678l; } char * func26() /* Pointer Return */ { static char x1[] = "abc"; STP_TRACE_D32(0, (unsigned int) &func26); STP_TRACE_D32(1, (unsigned int) x1); STP_TRACE_D32(2, (unsigned int) x1[0]); return x1; } struct struct1 func27( x1, x2 ) /* function returning struct */ short x1, x2; { ast.count = x1*x2; return ast; } main() { int j; char * p; int loops; vtripplearray[0][0][0] = 1; vtripplearray[1][0][0] = 2; vtripplearray[0][1][0] = 3; vtripplearray[0][0][1] = 4; func2(); funcptr = func3; ast.count = 12345; ast.left = * ast.field1 = 1; ast.field2 = 2; ast = func4( ast ); j = (*funcptr)(); start: j = func5( (int) j, (char) 2, (long) 3 ); if ( j == 0 ) goto start; vfloat = 2.0; func6( vfloat, (float) 3.0 ); vdouble = 2.0; func7( vdouble, (double) 3.0 ); func9(); func11( 5 ); func13( 1, 2, 3 ); func14( (char) 55 ); func15( (short) 55 ); func16( (long) 55 ); func17( (short) 44, (short) 55 ); func18( (short) 44, (long) 55 ); func19( (long) 44, (short) 55 ); func20( (short) 33, (short) 44, (short) 55 ); func21( (long) 33, (short) 44, (short) 55 ); func22( (short) 33, (long) 44, (short) 55 ); func23( (short) 33, (short) 44, (long) 55 ); j = func24(); j = func25(); p = func26(); loops = 0; while ( TRUE ) { sieve(loops++); } } char flags[SIZE+1]; int sieve(int loops) /* sieve of erathostenes */ { static int i, primz, k; int count; count = 0; if (!loops) STP_TRACE_D32(0, (unsigned int) &sieve); for ( i = 0 ; i <= SIZE ; flags[ i++ ] = TRUE ) ; for ( i = 0 ; i <= SIZE ; i++ ) { if ( flags[ i ] ) { primz = i + i + 3; k = i + primz; while ( k <= SIZE ) { flags[ k ] = FALSE; k += primz; } count++; if(!loops) { STP_TRACE_D32(1, (unsigned int) &primz); STP_TRACE_D32(2, (unsigned int) primz); } } } return count; }