3.3.1 Example 4 – Basic Usage 16-bit x 16-bit = 32-bit Integer Multiply

Below is an example of how to call the 16 x 16 = 32 multiply subroutine. This is also illustrated in the figure below.
ldi R23,HIGH(672)
ldi R22,LOW(672) ; Load the number 672 into r23:r22
ldi R21,HIGH(1844)
ldi R20,LOW(184) ; Load the number 1844 into r21:r20
call mul16x16_32 ; Call 16bits x 16bits = 32bits multiply routine
Figure 3-4. 16-bit Multiplication, 32-bit Result

The 32-bit result of the unsigned multiplication of 672 and 1844 will now be in the registers R19:R18:R17:R16. If “muls16x16_32” is called instead of “mul16x16_32”, a signed multiplication will be executed. If “mul16x16_16” is called, the result will be only 16 bits long and will be stored in the register pair R17:R16. In this example, the 16-bit result will not be correct.