(* ************************************************************ *
 *								*	
 *	      Program P (Print table of 500 primes)		*
 *								*
 *	rI1 = J - 500; rI2 = N; rI3 = K; rI4 indicates B; 	*
 *      rI5 is M plus multiples of 50				*
 *								*
 * ************************************************************ *)


		MIXAL

(* 
 *
 * EXAMPLE PROGRAM ... TABLE OF PRIMES 
 *
 *)


 500		EQU	L		\ number of primes to find
  18 		EQU	printer		\ unit number of printer
  -1 		EQU	prime		\ memory area for table of primes
2000 		EQU	buf0		\ memory area for BUFFER[0]
buf0 25 + 	EQU 	buf1		\ memory area for BUFFER[1]

		FWD 	title

	ORIG 	3000

| start	IOC	0(printer)		\ skip to new page
	LD1	= 1 L - =		\ _P1. Start table._ J <- 1
	LD2	= 3     =		\ N <- 3
| 2H	INC1	1			\ _P2. N is prime._ J <- J+1
	ST2	prime L + ,1		\ PRIME[J] <- N
	J1Z	2F			\ _P3. 500 found?_
| 4H	INC2	2			\ _P4. Advance N._
	ENT3	2			\ _P5. K <- 2._
| 6H	ENTA 	0			\ _P6. PRIME[K]\N?_
	ENTX	0,2
	DIV	prime,3
	JXZ	4B			\ R = 0?
	CMPA	prime,3			\ _P7. PRIME[K] large?_
	INC3	1			\ _P8. Advance K._
	JG	6B			\	Jump if Q > PRIME[K]	
	JMP	2B			\	Otherwise N is prime
| 2H	OUT	title(printer)		\ _P9. Print title._
	ENT4	buf1 10 +		\	Set B <- 1
	ENT5	-50			\	Set M <- 0
| 2H	INC5	L 1+			\	Advance M
| 4H	LDA	prime,5			\ _P10. Set up line._ (Right to left)
	CHAR 
	STX	0,4(1:4)
	DEC4	1
	DEC5	50			\ 	(rI5 goes down by 50 until
	J5P	4B			\	 	nonpositive)
	OUT	0,4(printer)		\ _P11. Print line._
	LD4	24,4			\	Switch buffers
	J5N	2B			\	If rI5 = 0, we are done.
	HLT

(*
 *
 * Initial contents of tables and buffers
 *
 *)

	ORIG	prime 1+
	CON	2			\ First prime is 2

	ORIG	buf0 5 -
| title	ALF FIRST			\ Alphabetic information for 
	ALF  FIVE			\ 	title line
	ALF  HUND
	ALF RED P
	ALF RIMES

	ORIG	buf0 24 +
	CON	buf1 10 +		\ Each buffer refers to the other

	ORIG	buf1 24 +
	CON	buf0 10 +

	END	start			\ End of routine

			        (* End of File *)