7.3.2 16x16 Unsigned Multiplication Algorithm

16x16 Unsigned Multiply Routine shows the sequence to do a 16x16 unsigned multiplication. 16x16 Unsigned Multiply Algorithm shows the algorithm that is used. The 32-bit result is stored in four registers.

16x16 Unsigned Multiply Algorithm

R E S 3 : R E S 0 = A R G 1 H : A R G 1 L A R G 2 H : A R G 2 L = ( A R G 1 H A R G 2 H 2 16 ) + ( A R G 1 H A R G 2 L 2 8 ) + ( A R G 1 L A R G 2 H 2 8 ) + ( A R G 1 L A R G 2 L )

16x16 Unsigned Multiply Routine

        MOVF    ARG1L, W
        MULWF   ARG2L           ; ARG1L * ARG2L → PRODH:PRODL
        MOVFF   PRODH, RES1     ;
        MOVFF   PRODL, RES0     ;
;
        MOVF    ARG1H, W        ;
        MULWF   ARG2H           ; ARG1H * ARG2H → PRODH:PRODL
        MOVFF   PRODH, RES3     ;
        MOVFF   PRODL, RES2     ;
;
        MOVF    ARG1L, W
        MULWF   ARG2H           ; ARG1L * ARG2H → PRODH:PRODL
        MOVF    PRODL, W        ;
        ADDWF   RES1, F         ; Add cross products
        MOVF    PRODH, W        ;
        ADDWFC  RES2, F         ;
        CLRF    WREG            ;
        ADDWFC  RES3, F         ;
;
        MOVF    ARG1H, W        ;
        MULWF   ARG2L           ; ARG1H * ARG2L → PRODH:PRODL
        MOVF    PRODL, W        ;
        ADDWF   RES1, F         ; Add cross products
        MOVF    PRODH, W        ; 
        ADDWFC  RES2, F         ;
        CLRF    WREG            ;
        ADDWFC  RES3, F         ;