; Scaling test
.equ myint = 54321 ; Value to be scaled
.equ coeff = 0.34567*65536 ; Scaling coefficient
;
ldi r16,low(myint)
ldi r17,high(myint)
movw r4,r16 ; r5r4 = myint = 54321
ldi r16,low(coeff)
ldi r17,high(coeff) ; r17r16 = coeff = 0.34567
rcall scale16
rjmp PC
;--------------------------------------------------------------------
; Scales unsigned int r5:r4 by r17:r16 value presented as unsigned fractional (0000 = 0, FFFF = 0.99998)
; Result stored in r9:r8
; 14 program words, 17 clocks + ret
;
scale16:
clr r2
mul r5,r17
movw r8,r0
mul r4,r16
movw r6,r0
mul r5,r16
add r7,r0
adc r8,r1
adc r9,r2
mul r4,r17
add r7,r0
adc r8,r1
adc r9,r2 ; r9r8 = 54321*0.34567=~0x4958=18776
ret