www.pudn.com > iccavr_lib.rar > emul32b.s, change:2003-11-08,size:1528b


	.text
empy32s::
empy32u::
;  think of one operand as consisting of bytes (high) A B C D (low)
; and the other operand as consisting of bytes (high) E F G H (low)
	.define	A R19
	.define	B R18
	.define	C R17
	.define	D R16
	.define	E R27
	.define	F R26
	.define	G R25
	.define	H R24

; inputs: R19..R16 multiplier
;	  R27..R24 multiplicand
; output: R8..R11  product
;	  R7	   overflow indicator if not zero

	rcall	long_prolog
	push R7	; rfm - done after long_prolog so the
		; end can still be a rjmp to long_epilog
	rcall	tstzero1	; this along with next step are optional
	breq	donemul		; exit if multiplier is zero
	clr	R7		; zero value and overflow accumualtor
	rcall	tstzero2	; this along with next step are optional
	brne gomul
	movw R16,R24
	movw R18,R26
	rjmp donemul
gomul:
	MUL	D,H
	mov	R11,R0
	mov	R10,R1
	MUL	B,H
	mov	R9,R0
	mov	R8,R1
	MUL	C,H
	add	R10,R0
	adc	R9,R1
	adc	R8,R7
	MUL	D,G
	add	R10,R0
	adc	R9,R1
	adc	R8,R7
	MUL	C,G
	add	R9,R0
	adc	R8,R1
	MUL	D,F
	add	R9,R0
	adc	R8,R1
	MUL	A,H
	add	R8,R0
	or	R7,R1
	MUL	B,G
	add	R8,R0
	or	R7,R1
	MUL	C,F
	add	R8,R0
	or	R7,R1
	MUL	D,E
	add	R8,R0
	or	R7,R1
	MUL	A,G
	or	R7,R0
	or	R7,R1
	MUL	B,F
	or	R7,R0
	or	R7,R1
	MUL	C,E
	or	R7,R0
	or	R7,R1
	MUL	A,F
	or	R7,R0
	or	R7,R1
	MUL	B,E
	or	R7,R0
	or	R7,R1
	MUL	A,E
	or	R7,R0
	or	R7,R1
moveresult:
; funky big endian order remap. "thanks" Everett
; You're welcome, Richard.  We aim to produce things in the
; well-known better order
	mov	r16,r11
	mov	r17,r10
	mov	r18,r9
	mov	r19,r8
donemul:
	pop	R7	; rfm
	rjmp	long_epilog