home *** CD-ROM | disk | FTP | other *** search
-
- Edward J. Joyce Copyright (c) 1986
-
-
- Illustrative Material to Accompany
-
-
- "MPS--Designed for Business Computing"
-
-
- Listing 1
-
- ; SIEVE.TXT -- Sieve of Eratosthenes benchmark program.
-
- ; Perform 10 iterations of calculating the 1899 prime numbers between
- ; 3 and 16,381.
-
- ; Data declarations.
- SIZE BIN "8191" ; array size
- ; (used as binary constant)
- ONEBIN "1"; constant
-
- FLAGS ARRAY BIN ; indicates primes
- COUNT NUM 4 ; counts primes found
- ; (4-character ASCII decimal field)
- ; binary variables
- I BIN ; indexes into FLAGS array
- K BIN ; indexes into FLAGS array
- PRIME BIN ; prime number
- ITER BIN "1" ; counts iterations
- ; (initialized to one)
-
-
- ; Executable instructions.
- CONVERSE *N,"10 iterations" ; do cr/lf & display msg
-
- ITERLOOP CLEAR COUNT ; initialize counter to zero
- DEFARRAY FLAGS,ONE,SIZE ; initialize array to all ones
- MOVE "1",I ; set index
-
- ARRLOOP SETIDX FLAGS,I ; set array index
- COMPARE "1",FLAGS ; prime?
- GOTO NOTPRIME IF NOT EQUAL ; no
- MOVE I,PRIME ; PRIME := I+I+3
- ADD I,PRIME
- ADD "3",PRIME
- MOVE I,K ; K := I+PRIME
-
- MULTLOOP ADD PRIME,K
- SETIDX FLAGS,K ; set array index &
- ; OVER flag if K > SIZE
- IF NOT OVER
- CLEAR FLAGS ; indicate non-prime
- GOTO MULTLOOP
- ENDIF รจ
- INCR COUNT ; increment primes found
-
- NOTPRIME COMPARE I,SIZE ; array done?
- IF NOT EQUAL
- INCR I ; no - increment array index
- GOTO ARRLOOP ; check next element
- ENDIF
-
- COMPARE "10",ITER ; 10 iterations done?
- IF NOT EQUAL
- INCR ITER ; no - increment iterations
- GOTO ITERLOOP ; do another iteration
- ENDIF
-
- CONVERSE *N,COUNT," primes" ; display primes found
- END
-
-
-
-
-
- Listing 1. An MPS version of the standard Sieve of Eratosthenes
- benchmark program.
-
-
-
- Listing 2
-
- ; data declarations
- FIND CHR "HI" ; string to be found
- LEN BIN "3" ; array length for search
- IDX NUM 2 ; holds result
-
- WORDS ARRAY CHR,3,8,FW ; allocates array
- ; 1st parm = array type, char
- ; 2nd parm = # of elements
- ; 3rd parm = length of each element
- ; 4th parm = label of first
- ; element
- FW CHR "HI " ; array is initialized from
- SW CHR "SO THERE" ; from this data
- TW CHR "WELLWELL"
-
- ; executable instruction
- BSEARCH FIND IN WORDS WITH LEN TO IDX