title: fast 8x8bit multiplication assembly pic18
body: <p>Im trying to multiply two 8 bit numbers and store them in a 16 bit location for results larger than 255. The fastest way to accomplish this is through shifting, which I have tried to implement via the rrcf function and using bcf to clear unwanted carries. </p>
  
  <p>This is what ive came up with. Ive tried to comment all the code so you are able to see my thought process. Im  fairly new to both the PIC18 and programming in ASM in general. Please keep that in mind when (hopefully) providing help. I need to get put in a better spot than I am in, when I run MPLAB SIM, all I get is the counter decrementing...? </p>
  
  <p>I think this is due to the last bit of multiplier being repeatedly tested, which will be zeros and and therefore skip my add instruction every time. Can you help me create a loop to move BTFSC progressively from bit 0-7? I think this is the problem, but i can't figure out the code. I could essentailly write main 8 times, but im trying to save code space</p>
  
  <pre><code>            LIST P=18F4550
              #include &lt;P18F4550.INC&gt;
  
              ;equates
              counter equ 0x00 ;set counter
              multiplicand equ 0x01 ;set multiplicand
              multiplier equ 0x02 ;set multiplier
              resultHigh equ 0x03 ;set resultHigh
              resultLow equ 0x04 ;set resultLow
  
              ;test program
  
              movlw d'100' ;move literal d'100' to wreg
              movwf multiplicand ;set multiplicand
              movlw d'400'       ;move literal d'400'
              movlw multiplier   ;set multiplier
              movlw d'8'         ;counter
              movwf counter      ;set counter
  
              main:
              btfsc multiplier, 0          ;test LSB if 0,skip next if 0
              addwf multiplier, resultLow  ;add if 1 to resultLow
              bcf STATUS,C                 ;clear carry flag
              rlcf multiplier              ;rotate multiplier left
              bcf STATUS,C                 ;clear carry
              rlcf resultLow               ;rotate resultLow w/ carry
              rlcf resultHigh              ;rotate resultHigh 
                                                                    ;w/carry from resultLow
  
              decf counter                 ;dec counter
              goto main                    ;repeat for 8 bits
              end
  </code></pre>