View previous topic :: View next topic |
Author |
Message |
RckRllRfg
Joined: 20 Jul 2011 Posts: 60
|
Multiply creates no code? |
Posted: Wed Dec 07, 2011 2:55 pm |
|
|
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
|
|
Posted: Wed Dec 07, 2011 10:55 pm |
|
|
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
|
|
Posted: Thu Dec 08, 2011 12:07 am |
|
|
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
|
Re: Multiply creates no code? |
Posted: Thu Dec 08, 2011 3:15 am |
|
|
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
|
|
Posted: Thu Dec 08, 2011 4:23 am |
|
|
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
|
A belated Thank you |
Posted: Mon Dec 12, 2011 1:36 pm |
|
|
Everyone -
Thank you for the clarification. I wanted to acknowledge it.
Regards -
RckRllRfg |
|
|
|