Most programming languages have a built-in implementation of exponentiation.



Task

Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition).

If the language supports operator (or procedure) overloading, then an overloaded form should be provided for both   intint   and   floatint   variants.



Related tasks

   Exponentiation order
   arbitrary-precision integers (included)
   Exponentiation with infix operators in (or operating on) the base


ExponentUnsigned:
	;input: D0.W = BASE
	;	D1.W = EXPONENT
	;	OUTPUTS TO D0
	;	NO OVERFLOW PROTECTION - USE AT YOUR OWN RISK!
	;HIGH WORDS OF D0 AND D1 ARE CLEARED.
	;clobbers D1
 
	MOVE.L D2,-(SP)
 
		;using DBRAs lets us simultaneously subtract and compare
		DBRA D1,.test_if_one
		MOVEQ.L #1,D0		;executes only if D1 was 0 to start with
.test_if_one:		
		DBRA D1,.go
		bra .done		;executes only if D1 was 1 to start with
.go:
		;else, multiply D0 by its ORIGINAL self repeatedly.
		MOVE.L D0,D2
.loop:
		MULU D0,D2
		DBRA D1,.loop
 
		MOVE.L D2,D0
.done:
	MOVE.L (SP)+,D2
	RTS