[net.arch] Checking for Overflow after a Multiply

joe@petsd.UUCP (Joe Orost) (07/29/85)

In article <600008@pbear.UUCP> peterb@pbear.UUCP writes:
>	It is trivial to determine overflow in a word X word = word
>operation. Just do the standard multiply producing 2*word bits and check the
>high order word for non-zero(base 1) values. If this is so, then to result
>has overflowed. This check can be built in and executed at the end of the
>multiply as the resultant lower word result is placed in the destination.
>
>	It is not that expensive, requiring a few clocks at best.

WRONG KEMOSABI!

An overflow occurs when the high-order word is not a replication of the sign
bit in the low order word.  Here is the code necessary on a Perkin-Elmer
3200 to check for overflow:

----------
	L	R15,First	--Load first operand in R15
	M	R14,Second	--Multiply - Result is in R14:R15
	LCS	R13,1		--R13 := -1;
	LR	R15,R15		--Test R15
	BM	$Label		--Branch if Minus
	LIS	R13,0		--R13 := 0;
$Label	CLR	R14,R13		--Compare R14 and R13
	BNE	.overflow	--Branch if not equal - overflow
	ST	R15,Result	--Store Result
----------

				regards,
				joe

--

 ........        .........	Full-Name:  Joseph M. Orost
 .       .       .		UUCP:       ihnp4!vax135!petsd!joe
 . ......   ...  ........	ARPA:	    vax135!petsd!joe@BERKELEY
 .               .		Phone:      (201) 758-7284
 .               .........	Location:   40 19'49" N / 74 04'37" W
				US Mail:    MS 313; Perkin-Elmer; 106 Apple St
					    Tinton Falls, NJ 07724