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

int32 multiply - higher 32bit result

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







int32 multiply - higher 32bit result
PostPosted: Mon Apr 20, 2009 3:02 am     Reply with quote

Hi, let me ask you whether there is a chance to get higher 32bits from following multiplication:
int32 a,b,c;
a = 0x17dc65de;
b = 0x1312d00;
c = a * b;
result is 1B660600 (lower 32bits from the result). I need the higher word 1C71C71 from the actual result 1C71C71B660600. Is there any trick how to access the higher 32bits? Thanks, pito.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Apr 20, 2009 3:21 am     Reply with quote

Using int64 type
piti2333
Guest







PostPosted: Mon Apr 20, 2009 3:40 am     Reply with quote

There in none int64 for smaller PICs. int64 for 24H &dspic only. pito
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Apr 20, 2009 4:35 am     Reply with quote

You didn't tell your PIC. But you can port Microchip AN0617 fixed point assembly routines.
piti2333
Guest







PostPosted: Mon Apr 20, 2009 5:09 am     Reply with quote

I am using pic16f876 (int64 does not work with 12,16,18, v4.084). I had used the stuff in #asm, however I am rewriting all the code to C for simplicity.
I've just found at www.cs.uaf.edu/~cs301/notes/Chapter5/node5.html
an nice algorithm which seems to works - based on that:

void long_multiply (int32 v1, int32 v2)
{
// HILO(64bit) = v1(32)*v2(32)
// glob: int32 HI, LO;
int32 a, b, c, d;
int32 x, y;
a = (v1 >> 16) & 0xffff; b = v1 & 0xffff;
c = (v2 >> 16) & 0xffff; d = v2 & 0xffff;
LO = b * d;
x = a * d + c * b;
y = ((LO >> 16) & 0xffff) + x;
LO = (LO & 0xffff) | ((y & 0xffff) << 16);
HI = (y >> 16) & 0xffff;
HI += a * c;
}
pito
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