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 support@ccsinfo.com

Hardware multiplication MULWF

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

Hardware multiplication MULWF
PostPosted: Thu Nov 08, 2007 11:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 08, 2007 11:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 08, 2007 1:21 pm     Reply with quote

Same result in the ancient v3.226 I'm using.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 08, 2007 1:38 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 08, 2007 2:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 08, 2007 3:14 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 08, 2007 3:19 pm     Reply with quote

still no joy on v3.249
but change to _mul and you get the mulwf
Code:
c = _mul(a,b);


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

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 08, 2007 3:31 pm     Reply with quote

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