;/* Title	: Recursive implementation of factorial */
;/* Author	: Jan Skalicky, 2005 */


	.include	"m169def.inc"

	.cseg
	.org 0

	jmp		init
	
	.include	"muldiv.asm"

/* stack init */
init:
	ldi		r20, high(RAMEND)
	out		sph, r20
	ldi		r20, low(RAMEND)
	out		spl, r20

/* start */
	ldi		r16, 6
	call	factor

looop:
	rjmp	PC

/* recursive factorisation r16->r17:r16 */
factor:
	tst		r16
	brne	recur
	clr		r16
	inc		r16
	ret
recur:
	push	r16
	dec		r16
	call	factor
	pop		r17
	call	mul8x8
	ret

