Hi, Your 32 bit addition is incorrect. It should be: movf twofour0,w addwf prod0,f movf twofour1,w btfsc STATUS,c incfsz twofour1,w addwf prod1,f movf twofour2,w btfsc STATUS,c incfsz twofour2,w addwf prod2,f movf twofour3,w btfsc STATUS,c incfsz twofour3,w addwf prod3,f regards, Reggie Saurabh Sinha wrote: > > Byron, > > Thank you for your code. I tried to run it, but I am having certain > problems. Take for example, > the following problem, in 2s complement. > > The following variable declerations are used: > > TWOFOUR2 B'00001000' Equivalent: c0=534035 (dec) > TWOFOUR1 B'00100110' > TWOFOUR0 B'00010011' > > MULTIPLIER B'00000111' Equivalent: u0=7 (dec) > > Result: (MPLAB) > > PROD2 B'00001000' Equivalent: c0u0 (dec) > PROD1 B'00100110' > PROD0 B'00010011' > > This does not seem to be the correct answer. > > Any ideas on where the error could possibly be, or is it just me getting > confused with 2's comp...? > > Thanks in advance for your help. > > Regards, > > Saurabh > ======================================================CODE > USED================================ > > mult24x8: > clrf prod0 ; Clear the product > clrf prod1 > clrf prod2 > clrf prod3 > clrf twofour3 ; Clear the top byte of the multiplicand > return > > multloop: > movf mulitiplier,W ; Check to see if eight bit is empty > btfsc STATUS,Z ; Done if zero > return > bcf STATUS,C ; clear carry > rrf mulitiplier,F ; Get the next bit > btfss STATUS,C ; Add if carry is set > goto multshift ; shift only if 0 > movf twofour0,W ; Add the 32 bits of multiplicand to product > addwf prod0,F ; each addwf sets the carry > btfsc STATUS,C ; Don't increment if no carry > incf prod1,F ; Add one to next byte if carry occured > movf twofour1,W ; > addwf prod1,F ; > btfsc STATUS,C ; Don't increment if no carry > incf prod2,F ; Add one to next byte if carry occured > movf twofour2,W ; > addwf prod2,F ; > btfsc STATUS,C ; Don't increment if no carry > incf prod3,F ; Add one to next byte if carry occured > movf twofour3,W ; > addwf prod3,F ; > > multshift: > bcf STATUS,C ; clear carry > rlf twofour0,F ; Shift the 24 bits one bit to the left > rlf twofour1,F > rlf twofour2,F > rlf twofour3,F > return > return