CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Multiply creates no code?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RckRllRfg



Joined: 20 Jul 2011
Posts: 60

View user's profile Send private message

Multiply creates no code?
PostPosted: Wed Dec 07, 2011 2:55 pm     Reply with quote

Hello Everyone -

In the midst of my coding, I need to multiple 2 numbers together. I was curious to see how the CCS compiler would respond; however, when looking at the .lst file, I simply do not see the multiplication happening. Here's an example piece of code. DummyVar1 and DummyVar2 are unsigned int8 and VRECvalueSqured is unsigned int16:

Code:


   VRECvalueSqured = _mul( DummyVar1, DummyVar2);




I also tried:

Code:


   VRECvalueSqured = DummyVar1 * DummyVar2;





The result from the .lst file:

Code:


03FB:  MOVLB  01
03FC:  MOVF   1C,W
03FD:  MOVLB  03
03FE:  MOVWF  5A
03FF:  MOVLB  01
0400:  MOVF   1B,W
0401:  MOVLB  03
0402:  MOVWF  5B
*
0427:  MOVF   78,W
0428:  MOVLB  00
0429:  MOVWF  25
042A:  MOVF   77,W
042B:  MOVWF  26



Basically, I see that this code is moving the values, but I do not see any shifting, adding, or looping.

I am using a 16F1947 with compiler 4.124

Any guidance is appreciated -

RckRllRfg
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Dec 07, 2011 10:55 pm     Reply with quote

Can you create a 10 to 20 line program containing the multiplication and post it so we can see what you get?
_________________
Every solution has a problem.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 12:07 am     Reply with quote

Code:
0402:  MOVWF  5B
*
0427:  MOVF   78,W

Notice the gap in instruction addresses. Try with out-commented "#nolist" preprocessor comment.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Multiply creates no code?
PostPosted: Thu Dec 08, 2011 3:15 am     Reply with quote

RckRllRfg wrote:


Basically, I see that this code is moving the values, but I do not see any shifting, adding, or looping.


You wont see any shifting, adding or looping. PICs, apart from the earliest 16 series types, have a 8 * 8 hardware multiply which the compiler will use in various combinations to scale up to 16 * 16 and so on. Your not going to see the classic long multiplication "shift and add" process.

That said, you're not seeing 8 * 8 mulitplies either, at least not in the code that's visible in your examples.

Quote:

I also tried:

Code:


   VRECvalueSqured = DummyVar1 * DummyVar2;




This will not produce the results you're expecting. You've declared both dummies as unsigned int8, so therefore the compiler will do the multiply in unsigned int8 arithmetic (which is a single mulitply instruction on the PIC). To get C - this is not a CCS issue - to do the arithmetic in unsigned int16 you need to cast one, or both, to unsigned int16, such as this:

Code:


   VRECvalueSqured = (int16)DummyVar1 * DummyVar2;



While CCS has a lot of bugs, simple, basic multiplcation is not suspected of being one of them!

RF Developer
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 4:23 am     Reply with quote

This is down to the #nolist option.
By default this is enabled (about the third line in all the processor include files). So code for 'hidden' libraries, by default is not shown. This is the '*' in the listing. This will be a call to the library mul8x8, or mul16x16 respectively.
If you rem out the nolist in the processor file, and save it (the compiler will ask if you are sure you want to do this - say yes), you will then see the code generated.

Best Wishes
RckRllRfg



Joined: 20 Jul 2011
Posts: 60

View user's profile Send private message

A belated Thank you
PostPosted: Mon Dec 12, 2011 1:36 pm     Reply with quote

Everyone -

Thank you for the clarification. I wanted to acknowledge it. Very Happy

Regards -

RckRllRfg
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group