Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #define RANGE 20000u
- #define RANGE_SQRT 141u
- //#define RANGE 10000u
- //#define RANGE_SQRT 100u
- // compiled with cl65 -t c64 -O --codesize 800 -Cl crivello.c Extern.s -o crivello.prg
- /*Extern.s
- .export _ScopeMax;
- _ScopeMax = $40
- .export _i;
- _i = $42
- .export _j;
- _j = $44
- .export _pr;
- _pr = $46
- .export _Parziale;
- _Parziale = $48
- */
- extern unsigned int ScopeMax;
- #pragma zpsym("ScopeMax")
- extern unsigned int i;
- #pragma zpsym("i")
- extern unsigned int j;
- #pragma zpsym("j")
- extern unsigned int pr;
- #pragma zpsym("pr")
- extern unsigned int Parziale;
- #pragma zpsym("Parziale")
- typedef unsigned char uint_8;
- uint_8 composite[RANGE+1];
- int main(void) {
- clock_t Ticks, TicksDelta;
- unsigned int Sec;
- unsigned int Milli;
- unsigned int pi=0;
- pr =0;
- for(j=1,i=2; j<RANGE; ++j) {
- composite[j]=0;
- composite[i]=1;
- ++j;
- i+=2;
- }
- j=3;
- Parziale=6;
- printf("\nComputing for PI(%u)...\n", RANGE);
- Ticks = clock();
- while(j<RANGE_SQRT) {
- ScopeMax=RANGE/j;
- pr=Parziale+j;
- for (i=3; i<=ScopeMax; i+=2) {
- composite[pr]=1;
- pr+=Parziale;
- }
- j+=2;
- Parziale+=4;
- }
- TicksDelta = clock() - Ticks;
- Sec = (unsigned short) (TicksDelta / CLOCKS_PER_SEC);
- Milli = ((TicksDelta % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
- printf ("Time used: %u.%03u seconds = %u ticks\n", Sec, Milli, (unsigned short) TicksDelta);
- printf("Press enter to print the prime numbers\n");
- getchar();
- printf("\n");
- composite[1]=1;
- composite[2]=0;
- for(i=1; i<RANGE+1; ++i) {
- if(composite[i]==0) {
- ++pi;
- printf(" %u ", i);
- }
- }
- printf("\nPi = %u", pi);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement