/ 
/  mult.pal
/
/  Started by Jeff Ondich on 9/17/96
/  Last modified 9/18/96
/
/  This PDP8 program illustrates some simple features of
/  the PAL assembly language.  It consists of a call to a
/  simple-minded multiplication subroutine, and leaves
/  the product in the AC when the program terminates.
/

*0200

MAIN,		CLA					/ Set up AC for call to MULT
			TAD ADDRESS
			JMS MULT			/ Call MULT
			HLT	

ADDRESS,	F1					/ Address of first factor
F1,			0003				/ First factor
F2,			0004				/ Second factor


/  MULT multiplies two non-negative integers, leaving
/  the product in the AC upon return.  If the product
/  overflows 12 bits, the answer will be wrong.
/  
/  When MULT is called, the AC should contain the
/  address of the first of two one-word factors stored
/  in consecutive memory locations.
/
/  If you were concerned only about conserving memory
/  and not about readability, how might you shorten
/  this code?

MULT,		0000
			DCA ADDR			/ Transfer the first factor into
			TAD I ADDR			/   temporary location FACTOR.
			DCA FACTOR
			ISZ ADDR			/ Store -(second factor + 1)
			NOP					/   in COUNTER.
			TAD I ADDR
			CMA
			DCA COUNTER 
			DCA PRODUCT			/ Initialize the product to 0
			
LOOP,		ISZ COUNTER			/ Add FACTOR to PRODUCT
			SKP					/   and increment COUNTER
			JMP END				/   until COUNTER = 0.
			TAD FACTOR			/   This is A*B by way of
			TAD PRODUCT			/   adding up B copies of A.
			DCA PRODUCT
			JMP LOOP

END,		TAD PRODUCT			/ AC is clear before now, so
								/   this loads product into AC
			JMP I MULT			/ Return to caller

FACTOR,		0
COUNTER,	0
PRODUCT,	0
ADDR,		0




Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057, (507) 646-4364, jondich@carleton.edu