Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
; 8x8 unsigned multiply routine.
; No checks made for M1 or M2 equal to zero
Clrf R_hi ; Clear result location
movlw 0x08 ; setup loop count
movf M1,W ; initialize W with M1
Umul rrf M2,F ; rotate into carry to check bits
Btfsc STATUS,C ; if carry set i.e. bit was 1
addwf R_hi,F ; ... we add
rrf R_hi,F ; shift over for the next addition
decf cntr,F ; check the loop count
That simple loop multiplication is very slow though, if you start running out of processor time there are other multiplication routines out there that use more code space but take significantly less time to run.