Searching \ for 'multiplication routing 24x8' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=multiplication
Search entire site for: 'multiplication routing 24x8'.

Truncated match.
PICList Thread
'multiplication routing 24x8'
2000\03\22@193352 by Saurabh Sinha

picon face
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

2000\03\23@003505 by Regulus Berdin

picon face
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:
{Quote hidden}

2000\03\23@014401 by Saurabh Sinha

picon face
Hi,

Sorry, this still does not work. (I think!)

     TWOFOUR0    B'00010011'
     TWOFOUR1    B'00100110'
     TWOFOUR2    B'00000000'
     TWOFOUR3    B'00000000'
     PROD0       B'00010011'
     PROD1       B'00100110'
     PROD2       B'00000000'
     PROD3       B'00000000'
     MULITIPLIER B'00000111'

if I use the code below.

Thanks in advance for taking a look.

Regards,

Saurabh

==============================================
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
       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

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
==============================================

2000\03\23@015223 by Byron A Jeff

face picon face
{Quote hidden}

It's not. It's the partial product generated when you add the original
multiplicand to the first product, namely 0. Note that it's exactly the
same as the original number in TWOFOUR.
>
> Any ideas on where the error could possibly be, or is it just me getting
> confused with 2's comp...?

Sure. The program didn't loop to multloop so it never finished the
multiplication.

I'm sure I said that I generated that code off the top of my head. Just checked
the archive and the goto at the bottom of the loop is there.

I've now compiled it with picasm and tested it with gpsim on my Linux box.
Surprisingly enough I nailed it the first time. It does generate the
expected result if the goto is listed at the bottom of the routine.

Also note that I set up mult24x8 as a subroutine to be called.

>
> Thanks in advance for your help.

No problem.

{Quote hidden}

         goto    multloop ; need to add all partial products.

>  return ; Neither of these returns are required.
> return ; The routine will return when the multiplier is 0.

>

2000\03\23@015857 by Jason Harper

picon face
> mult24x8:
>         clrf    prod0           ; Clear the product
>         clrf    prod1
>         clrf    prod2
>         clrf    prod3
>         clrf    twofour3        ; Clear the top byte of the multiplicand
> return

The total effect of calling this routine is to clear these five variables.
The rest of the code is irrelevant since it is unreachable.  Get rid of
this bogus 'return', and replace the two 'return's at the very bottom with
a 'goto multloop', and it should work.
       Jason Harper

2000\03\23@022535 by Saurabh Sinha

picon face
Byron,

Thank you for your code.  It is 100%........

Regards,

Saurabh


----- Original Message -----
From: Byron A Jeff <spam_OUTbyronTakeThisOuTspamCC.GATECH.EDU>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Thursday, March 23, 2000 8:50 AM
Subject: Re: multiplication routing 24x8


{Quote hidden}

checked
{Quote hidden}

product
{Quote hidden}

2000\03\23@023806 by Byron A Jeff

face picon face
>
> Hi,
>
> Sorry, this still does not work. (I think!)

I still don't see the goto at the bottom of the routine and the returns at
the bottom are still in plae.

{Quote hidden}

How exactly are you defining these values above? It's looks like you're
doing equates. Let me give you the rest of the setup code I used for my test:


prod0           equ     20
prod1           equ     21
prod2           equ     22
prod3           equ     24

twofour0        equ     25
twofour1        equ     26
twofour2        equ     27
twofour3        equ     28

multiplier      equ     29


STATUS                       EQU     H'0003'
C                            EQU     H'0000'
Z                            EQU     H'0002'
W                               EQU     0
F                               EQU     1

       movlw   7
       movwf   multiplier
;TWOFOUR2 B'00001000'  ; Equivalent: c0=534035 (dec)
       movlw   B'00001000'  ;
       movwf   twofour2
;TWOFOUR1 B'00100110'
       movlw   B'00100110'  ;
       movwf   twofour1
;TWOFOUR0 B'00010011'
       movlw   B'00010011'  ;
       movwf   twofour0
       call    mult24x8
loop    goto    loop


{Quote hidden}

2000\03\23@040003 by Regulus Berdin

picon face
Hi,

I think the routine may not work on some values because of the 32 bit
addition.  The carry will not be passed to prod2 if prod1 is 0xFF and
there is a carry from the last addition of prod0 and twofour0.  Example:
0xFFFFFF * 3 will have and erroneous result.

regards,
Reggie


Saurabh Sinha wrote:
>
> Byron,
>
> Thank you for your code.  It is 100%........
>
> Regards,
>
> Saurabh
>
> {Original Message removed}

2000\03\23@231254 by Byron A Jeff

face picon face
>
> Hi,
>
> I think the routine may not work on some values because of the 32 bit
> addition.  The carry will not be passed to prod2 if prod1 is 0xFF and
> there is a carry from the last addition of prod0 and twofour0.  Example:
> 0xFFFFFF * 3 will have and erroneous result.

Agreed. There needs to be some additional code to propogate the carry all the
way through. Let me take a stab at it.

The updates are below. I tested them and they seem to work OK.

BAJ
{Quote hidden}

> > {Original Message removed}

2000\03\24@005210 by Regulus Berdin

picon face
Hi Byron,

There is a generic multibyte addition routine that is on the Microchip
docs.  I don't know who made it but works like a charm.

;A = A + B

       movf    B0,w
       addwf   A0,f            ; add LSB

       movf    B1,w            ; W = next byte
       skpnc                   ; skip next instr if there's a carry
        incfsz B1,w            ; inc W and skip next if B1 = 0xFF, C is still set
         addwf A1,f            ; add it except if C and B1 = 0xFF

       movf    B2,w            ; carry is propagated here if B1 was 0xFF
       skpnc                   ; and C was set
        incfsz B2,w            ; or from the last addition
         addwf A1,f

       movf    B3,w
       skpnc
        incfsz B3,w
         addwf A3,f

       .
       .
       .

subtraction is also similar:

; A = A - B

       movf    B0,w
       subwf   A0,f

       movf    B1,w
       skpc
        incfsz B1,w
         subwf A1,f

       .
       .
       .

regards,
Reggie


Byron A Jeff wrote:
{Quote hidden}

> > > {Original Message removed}

2000\03\24@032208 by Dwayne Reid

flavicon
face
<x-flowed>At 01:14 PM 3/24/00 +0800, Regulus Berdin wrote:
{Quote hidden}

same kind of typo that crept into my post:
the line 'addwf A1,f' (above) should be 'addwf A2,f'

>         movf    B3,w
>         skpnc
>          incfsz B3,w
>           addwf A3,f

dwayne



Dwayne Reid   <dwaynerspamKILLspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 16 years of Engineering Innovation (1984 - 2000)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

</x-flowed>

2000\03\24@094622 by Byron A Jeff

face picon face
{Quote hidden}

I see. It basically does the same carry propogation I did in line instead
of out of sequence.

BAJ

{Quote hidden}

2000\03\24@104523 by jamesnewton

face picon face
I've updated the web site to:

mult24x8:
       clrf    prod0           ; Clear the product
       clrf    prod1
       clrf    prod2
       clrf    prod3
       clrf    twofour3        ; Clear the top byte of the multiplicand
multloop:
       movf    eight,W         ; Check to see if eight bit is empty
       btfsc   STATUS,Z        ; Done if zero
       return
       bcf     STATUS,C        ; clear carry
       rrl     eight,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
       call    carryprop1      ; Propigate carry to next byte(s)
       movf    twofour1,W      ;
       addwf   prod1,F         ;
       btfsc   STATUS,C        ; Don't increment if no carry
       call    carryprop2      ; Propigate carry to next byte(s)
       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
       goto    multloop

carryprop1:
       incfsz  prod1,F
       return
carryprop2:
       incfsz  prod2,F
       return
carryprop3:
       incf    prod3,F
       return

Please let me know if this is not correct.

---
James Newton .....jamesnewtonKILLspamspam.....geocities.com 1-619-652-0593
http://techref.massmind.org NEW! FINALLY A REAL NAME!
Members can add private/public comments/pages ($0 TANSTAAFL web hosting)


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...