Hades logo    Hades applet banner

TAMS / Java / Hades / applets (print version): contents | previous | next

Mips R3051: prime numbers (1024 elements)

Mips R3051: prime numbers (1024 elements) screenshot

Description

This applet demonstrates yet another simple algorithm to calculate prime numbers. Detected prime numbers are stored in an array starting at program address 0x00000400, corresponding to memory component address 0x0100.

FIXME: This needs to be updated. Sorry.

#include "initcode.h"

void prim(int max, int startadr)
{
  int prim, teiler, *adr, teilt;
  
  adr = (void*) startadr;
  *adr = 2;

  for (prim = 3; prim < max; prim += 2) {
    teiler = 3;
    teilt = 0;
    while (teiler * teiler <= prim) {
      if (prim % teiler == 0) {
        teilt = 1;
        teiler = prim;
      } else {
        teiler += 2;
      }
    }
    if (teilt == 0) {
      adr++;
      *adr = prim;
    }
  }
}

void waitloop( void ) {
  int i, *ptr;
  ptr = (void*) (0x0400 - 32);
  for( i=0;; i++ ) {
    *(ptr) = i;
  }
}

int main(void)
{
  prim(0x400, 0x400);
  waitloop();
}
    

Run the applet | Run the editor (via Webstart)


Impressum | 24.11.06
http://tams.informatik.uni-hamburg.de/applets/hades/webdemos/76-mips/65-prim/prim_print.html