;/* Title	: Fixed point math routines for AVR */
;/* Author	: Jan Skalicky, 2005 */
;/* Content : mul8x8	| Multiplication 8x8->16b	| r17:r16 = r16*r17 			*/
;/* 		  div8x8	| Divison, Modulo 8x8->8b   | r16 = r16/r17; r17 = r16\r17  */


mul8x8:
	push	r18
	push	r19

	mov		r18, r17
	clr		r17
	ldi		r19, 9
	clc

mul8x8_loop:	
	ror		r17
	ror		r16
	brcc	PC+2
	add		r17, r18
	dec		r19
	brne	mul8x8_loop

	pop		r19
	pop		r18
	ret


div8x8:
	push	r18
	push	r19

	mov		r18, r17
	clr		r17
	ldi		r19, 8

div8x8_loop:	
	lsl		r16
	rol		r17
	cp		r17, r18
	brlo	PC+3
	sub		r17, r18
	inc		r16
	dec		r19
	brne	div8x8_loop

	pop		r19
	pop		r18
	ret
