Search code examples
assemblycpu-registersmicrochip

How does mulw, prodl and prodh work together in assembler programming?


I don't understand how the instruction MULLW and the registers PRODL and PRODH work. I have this piece of code:

        MOVLW 0x0D
        MULLW 0x09
        MOVF PRODL,W

What is it that actually happens? I've been trying to AND the values, which seems logic when it comes to multiplication:

0000 1101

0000 1001

But that would give 0x09 which is wrong. The answer, which is moved to PRODL, is 0x75. I have no idea how it became 0x75, I've tried all gates on the values but nothing makes sense. On the Internet, all I find about mullw, PRODL and PRODH is the manual for assembler which doesn't show each step on the way that explains why the answer becomes what it becomes.

All I know is that there is some initial operation with 16 bits and that the low value and high value of the result (no idea about the process) is placed in PRODL and PRODH respectively.

Could someone who knows about PRODL, PRODH and MULLW please explain this with an example and in detail?

Thank you.


Solution

  •         MOVLW 0x0D
            MULLW 0x09     
    

    0x0D x 0x09 = 0x0075

    After this instruction is PRODH = 0x00 and PRODL = 0x75
    PRODL and PRODH are both 8 Bit register which together hold the 16 Bit result. Just LSB and MSB.