View previous topic :: View next topic |
Author |
Message |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
Hardware multiplication MULWF |
Posted: Thu Nov 08, 2007 11:50 am |
|
|
Am I wrong to expect to find a few MULWF asm instruction in my list file.
Does the compiler use the hardware mul if it is available?
Does anyone do/force this an a known good workable way?
I thought that is what the _mul() function did. but it doesn't seem to be the
case in 3.249 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 08, 2007 11:58 am |
|
|
The code below was compiled with PCH vs. 4.062. It uses MULWF.
Quote: |
.... c = a * b;
0014: MOVF 06,W
0016: MULWF 07
0018: MOVF FF3,W
001A: CLRF 09
001C: MOVWF 08
|
Code: |
#include <18F452.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
//=========================
void main()
{
int8 a, b;
int16 c;
c = a * b;
while(1);
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Nov 08, 2007 1:21 pm |
|
|
Same result in the ancient v3.226 I'm using. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 08, 2007 1:38 pm |
|
|
It's possible that you're not seeing the code because it's hidden.
Some library routines are not normally shown in the .LST file.
To see them, edit the .H file for your PIC and comment out the
#nolist statement. Example:
Quote: |
#device PIC18F452
//#nolist
|
Then re-compile and look near the start of the .LST file. You should now
see the library routines with the MULWF statements. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Nov 08, 2007 2:58 pm |
|
|
The simple case ref: above does show the mulwf... so I guess i just
have to dumb down the code so the compiler sees it as a
int16 =int8 * int8
Thanks... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 08, 2007 3:14 pm |
|
|
The code that I posted above won't actually work. You have to cast
one of the variables to an int16 to get the correct result. But the
LST file code still uses the hardware multiply.
Quote: |
0004: MOVF 0C,W
0006: MULWF 0E
0008: MOVFF FF3,01
000C: MOVFF FF4,00
0010: MULWF 0F
0012: MOVF FF3,W
0014: ADDWF 00,F
0016: MOVF 0D,W
0018: MULWF 0E
001A: MOVF FF3,W
001C: ADDWFC 00,W
001E: MOVWF 02
0020: GOTO 0056 (RETURN)
|
I tried it with the _mul() routine and it creates code for a software
multiply. Now I understand the reason why you posted the question.
The method shown below should work for you.
Code: |
#include <18F452.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//=======================================
void main()
{
int8 a, b;
int16 c;
a = 250;
b = 133;
c = a * (int16)b;
printf("%lu", c);
while(1);
} |
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Nov 08, 2007 3:19 pm |
|
|
still no joy on v3.249
but change to _mul and you get the mulwf
Don't sweat it. All my code is working.
Just optimizing,.. trying to understand. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Nov 08, 2007 3:31 pm |
|
|
I think it just happens that my large programs all are using the mullw
(Multiply Literal with W)
so no mulwf.. sorry for the confusion. |
|
|
|