home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / CLDEC87.ZIP / EXOTIC.LTG < prev    next >
Encoding:
Text File  |  1987-11-23  |  3.6 KB  |  101 lines

  1.  
  2. Edward J. Joyce                              Copyright (c) 1986
  3.  
  4.  
  5.                Illustrative Material to Accompany
  6.  
  7.  
  8.              "MPS--Designed for Business Computing"
  9.  
  10.  
  11. Listing 1
  12.  
  13. ; SIEVE.TXT -- Sieve of Eratosthenes benchmark program. 
  14.  
  15. ; Perform 10 iterations of calculating the 1899 prime numbers between
  16. ;  3 and 16,381.
  17.  
  18. ; Data declarations.
  19. SIZE    BIN        "8191"               ; array size
  20.                                         ;  (used as binary constant)
  21. ONEBIN   "1"; constant 
  22.         
  23. FLAGS   ARRAY      BIN                  ; indicates primes
  24. COUNT   NUM        4                    ; counts primes found
  25.                                         ;  (4-character ASCII decimal field)
  26. ; binary variables
  27. I       BIN                             ; indexes into FLAGS array
  28. K       BIN                             ; indexes into FLAGS array
  29. PRIME   BIN                             ; prime number        
  30. ITER    BIN        "1"                  ; counts iterations  
  31.                                         ;  (initialized to one)
  32.  
  33.  
  34. ; Executable instructions.
  35.         CONVERSE   *N,"10 iterations"        ; do cr/lf & display msg
  36.         
  37. ITERLOOP  CLEAR      COUNT                   ; initialize counter to zero
  38.           DEFARRAY   FLAGS,ONE,SIZE          ; initialize array to all ones
  39.           MOVE       "1",I                   ; set index
  40.  
  41. ARRLOOP     SETIDX     FLAGS,I               ; set array index 
  42.             COMPARE    "1",FLAGS             ; prime?
  43.             GOTO       NOTPRIME IF NOT EQUAL ;  no
  44.               MOVE       I,PRIME             ; PRIME := I+I+3
  45.               ADD        I,PRIME
  46.               ADD        "3",PRIME
  47.               MOVE       I,K                 ; K := I+PRIME
  48.  
  49. MULTLOOP      ADD        PRIME,K
  50.               SETIDX     FLAGS,K             ; set array index &
  51.                                              ;  OVER flag if K > SIZE  
  52.               IF NOT OVER                    
  53.                 CLEAR      FLAGS             ; indicate non-prime
  54.                 GOTO       MULTLOOP
  55.               ENDIF รจ               
  56.               INCR       COUNT               ; increment primes found
  57.  
  58. NOTPRIME    COMPARE    I,SIZE                ; array done?
  59.             IF NOT EQUAL
  60.               INCR       I                   ;  no - increment array index
  61.               GOTO       ARRLOOP        ; check next element 
  62.             ENDIF
  63.  
  64.           COMPARE    "10",ITER               ; 10 iterations done?
  65.           IF NOT EQUAL
  66.             INCR       ITER                  ;  no - increment iterations
  67.             GOTO       ITERLOOP     ; do another iteration
  68.           ENDIF
  69.  
  70.         CONVERSE   *N,COUNT," primes"        ; display primes found
  71. END                   
  72.  
  73.  
  74.  
  75.  
  76.  
  77. Listing 1. An MPS version of the standard Sieve of Eratosthenes 
  78. benchmark program.
  79.  
  80.  
  81.  
  82. Listing 2
  83.  
  84. ; data declarations
  85.      FIND   CHR     "HI"           ; string to be found
  86.      LEN    BIN     "3"            ; array length for search
  87.      IDX    NUM     2              ; holds result
  88.      
  89.      WORDS  ARRAY   CHR,3,8,FW     ; allocates array
  90.                                    ;  1st parm = array type, char
  91.                                    ;  2nd parm = # of elements
  92.                                    ;  3rd parm = length of each element
  93.                                    ;  4th parm = label of first
  94.                                    ;   element 
  95.      FW     CHR     "HI      "     ; array is initialized from 
  96.      SW     CHR     "SO THERE"     ;  from this data
  97.      TW     CHR     "WELLWELL"     
  98.  
  99. ; executable instruction
  100.     BSEARCH FIND IN WORDS WITH LEN TO IDX
  101.