Searching \ for 'Multiplication' 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'.

Truncated match.
PICList Thread
'Multiplication'
1997\02\24@155204 by David Novak

flavicon
face
Why can't I use multiplication with MPLABC and the 16C63? I get all kinds
of errors when I attempt it. Is it not possible, or am I doing something
wrong?

Thanks,
David Novak
Hopkins Mfg.
spam_OUTnovakTakeThisOuTspamvalu-line.net

1997\02\24@182750 by Andy Kunz

flavicon
face
At 02:44 PM 2/24/97 -0600, you wrote:
>Why can't I use multiplication with MPLABC and the 16C63? I get all kinds
>of errors when I attempt it. Is it not possible, or am I doing something
>wrong?

The 16C parts don't have hardware multiply.

If using software, how about posting the routine.

Andy
==================================================================
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865
         Hardware & Software for Industry & R/C Hobbies
       "Go fast, turn right, and keep the wet side down!"
==================================================================

1997\02\25@125957 by David Novak

flavicon
face
This code:

long i, j;
i =j*5;

causes these errors:

ERROR   C:\MPLAB\MPLABC14.LIB 20:16:ILLEGAL OR UNDEFINED ARGUMENT _t 1
ERROR   C:\MPLAB\MPLABC14.LIB 21:7:EXPECTED  ;,
ERROR   C:\MPLAB\MPLABC14.LIB 21:7:EXPECTED  , got s
ERROR   C:\MPLAB\MPLABC14.LIB 24:5:ILLEGAL OR UNDEFINED ARGUMENT R1 .. 6
ERROR   C:\MPLAB\MPLABC14.LIB 25:5:ILLEGAL OR UNDEFINED ARGUMENT R1 .. 6
ERROR   C:\MPLAB\MPLABC14.LIB 26:5:ILLEGAL OR UNDEFINED ARGUMENT R1 .. 6
ERROR   C:\MPLAB\MPLABC14.LIB 27:12:ILLEGAL OR UNDEFINED ARGUMENT R1 .. 6
ERROR   C:\MPLAB\MPLABC14.LIB 35:14:ILLEGAL OR UNDEFINED ARGUMENT _r 2
ERROR   C:\MPLAB\MPLABC14.LIB 36:14:ILLEGAL OR UNDEFINED ARGUMENT _q 2
ERROR   C:\MPLAB\MPLABC14.LIB 37:14:ILLEGAL OR UNDEFINED ARGUMENT _s 2


I find this very disturbing since a file named ctutor.c which shipped with
the compiler contains this code:

#include <16c54.h>
#include <math.h>

unsigned int  Num1=2, Num2=3;           // Declare two eight bit numbers.
unsigned long Num3;                     // Declare one long for the result.
unsigned int  Num3High @ &Num3+1;       // Create an address for the top
byte.

void main() {
  while(1) {
     Num3 = Num1 * Num2;               // Multiply the two bytes into a
long.
     }
  }


Thanks,
David Novak
Hopkins Mfg.
.....novakKILLspamspam@spam@valu-line.net

----------
> From: Andy Kunz <montanaspamKILLspamFAST.NET>
> To: .....PICLISTKILLspamspam.....MITVMA.MIT.EDU
> Subject: Re: Multiplication
> Date: Monday, February 24, 1997 5:25 PM
>
> At 02:44 PM 2/24/97 -0600, you wrote:
> >Why can't I use multiplication with MPLABC and the 16C63? I get all
kinds
{Quote hidden}


'Multiplication'
2000\03\11@121858 by Saurabh Sinha
picon face
part 0 16 bytes
</x-html>

2000\03\11@124840 by Byron A Jeff

face picon face
> Hi,
>
> I needed some help in multiplication.
>
> I needed to multiply a 24 and a 8 bit number -> result 32 bits

You can do it the old fashioned shift and add method. Take the 24 bit
value and for each of the 8 bits, shift it one bit to the left. The rlf
instruction for each of the 4 bytes (because once you start shifting the
24 bits will expand to 32 bits) will do the job. Then for each bit in the
8 bit multiplicand, if it's a one add it to the product.

Something like this:
--------------------
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
       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
       goto    multloop
------------------------------------------------------------

I wrote this off the top of my head and I haven't tested it, but it should be
in the ballpark.

Not speedy, but should work.

BAJ
>
> Also, could someone please explain how the comf instruction works...
>
> eg. comf 1111 -> 0000 ? Is that right?

Yes. it just flips each bit.

BAJ

2000\03\13@115202 by jamesnewton

face picon face
See:
http://www.piclist.com/faq
under routines / math / basic math

Also, please don't post in HTML to the PICList. See
http://www.piclist.com

---
James Newton (PICList Admin #3)
EraseMEjamesnewtonspam_OUTspamTakeThisOuTpiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org


-----Original Message-----
From: pic microcontroller discussion list [PICLISTspamspam_OUTMITVMA.MIT.EDU]On
Behalf Of Saurabh Sinha
Sent: Saturday, March 11, 2000 09:17
To: @spam@PICLISTKILLspamspamMITVMA.MIT.EDU
Subject: Multiplication


Hi,

I needed some help in multiplication.

I needed to multiply a 24 and a 8 bit number ==> result 32 bits

Also, could someone please explain how the comf instruction works...

eg. comf 1111 = 0000 ? Is that right?

Thanks in advance for your help.

Saurabh

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