Shop OBEX P1 Docs P2 Docs Learn Events
Unsigned 32bx16b multiply subroutine — Parallax Forums

Unsigned 32bx16b multiply subroutine

Hello,
I thought that I would post a short 32bx16b unsigned multiply subroutine that is only 7 instructions long, not counting the return, which runs in 14 clocks.
Please note that the multiplicand is destroyed upon subroutines exit.

HydraHacker
Unsgnd32x16Mul
			
			getword		pl, mc, #1 				' get high word of mc into pl
			mul		pl, mp					' multiply high word of pl with low word of the mp
			getword		ph, pl, #1				' shift product in pl and ph left by 16 bits
			shl		pl, #16						
			mul		mc, mp					' multiply low word of mc by the low word of the mp
			add		pl, mc		wc			' add mc into pl
			addx		ph, #0					' add carry to ph
			ret	

mc			res	1						' multiplacand 
mp			res	1						' multiplier
pl			res	1						' product low
ph			res	1						' product high


Comments

Sign In or Register to comment.