2.3 Example 3 – Multiply-accumulate Operation

The final example of 8-bit multiplication shows a multiply-accumulate operation. The general formula can be written as:

c(n) = a(n) × b + c(n – 1)

; r17:r16 = r18 * r19 + r17:r16
in r18,PINB ; Get the current pin value on port B
ldi r19,b ; Load constant b into r19
muls r19,r18 ; r1:r0 = variable A * variable B
add r16,r0 ; r17:r16 += r1:r0
adc r17,r1

Typical applications for the multiply-accumulate operation are FIR (Finite Impulse Response) and IIR (Infinite Impulse Response) filters, PID regulators and FFT (Fast Fourier Transform). For these applications the FMULS instruction is particularly useful. The main advantage of using the FMULS instruction instead of the MULS instruction is that the 16-bit result of the FMULS operation always may be approximated to a (welldefined) 8-bit format. This is discussed further in the Using Fractional Numbers section.