Advertisement
EmanueleBonin

YAES - Page 0

Jul 11th, 2019
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. #define RANGE 20000u
  5. #define RANGE_SQRT 141u
  6. //#define RANGE 10000u
  7. //#define RANGE_SQRT 100u
  8. // compiled with cl65  -t c64 -O --codesize 800 -Cl crivello.c Extern.s -o crivello.prg
  9.  
  10. /*Extern.s
  11. .export _ScopeMax;
  12. _ScopeMax = $40
  13.  
  14. .export _i;
  15. _i = $42
  16.  
  17. .export _j;
  18. _j = $44
  19.  
  20. .export _pr;
  21. _pr = $46
  22.  
  23. .export _Parziale;
  24. _Parziale = $48
  25. */
  26.  
  27.  
  28.  
  29. extern unsigned int ScopeMax;
  30. #pragma zpsym("ScopeMax")
  31.  
  32. extern unsigned int i;
  33. #pragma zpsym("i")
  34.  
  35. extern unsigned int j;
  36. #pragma zpsym("j")
  37.  
  38. extern unsigned int pr;
  39. #pragma zpsym("pr")
  40.  
  41. extern unsigned int Parziale;
  42. #pragma zpsym("Parziale")
  43.  
  44. typedef unsigned char uint_8;
  45.  
  46. uint_8 composite[RANGE+1];
  47.  
  48.  
  49. int main(void) {
  50.     clock_t Ticks, TicksDelta;
  51.     unsigned int Sec;
  52.     unsigned int Milli;
  53.  
  54.  
  55.     unsigned int pi=0;
  56.     pr =0;
  57.  
  58.     for(j=1,i=2; j<RANGE; ++j) {
  59.         composite[j]=0;
  60.         composite[i]=1;
  61.         ++j;
  62.         i+=2;
  63.     }
  64.     j=3;
  65.     Parziale=6;
  66.     printf("\nComputing for PI(%u)...\n", RANGE);
  67.     Ticks = clock();
  68.     while(j<RANGE_SQRT) {
  69.         ScopeMax=RANGE/j;
  70.         pr=Parziale+j;
  71.         for (i=3; i<=ScopeMax; i+=2) {
  72.             composite[pr]=1;
  73.             pr+=Parziale;
  74.         }
  75.         j+=2;
  76.         Parziale+=4;
  77.     }
  78.     TicksDelta = clock() - Ticks;
  79.     Sec = (unsigned short) (TicksDelta / CLOCKS_PER_SEC);
  80.     Milli = ((TicksDelta % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
  81.     printf ("Time used: %u.%03u seconds = %u ticks\n", Sec, Milli, (unsigned short) TicksDelta);
  82.  
  83.     printf("Press enter to print the prime numbers\n");
  84.     getchar();
  85.     printf("\n");
  86.     composite[1]=1;
  87.     composite[2]=0;
  88.     for(i=1; i<RANGE+1; ++i) {
  89.         if(composite[i]==0) {
  90.             ++pi;
  91.             printf(" %u ", i);
  92.         }
  93.     }
  94.     printf("\nPi = %u", pi);
  95.  
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement