View previous topic :: View next topic |
Author |
Message |
piti2333 Guest
|
int32 multiply - higher 32bit result |
Posted: Mon Apr 20, 2009 3:02 am |
|
|
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
|
|
Posted: Mon Apr 20, 2009 3:21 am |
|
|
Using int64 type |
|
|
piti2333 Guest
|
|
Posted: Mon Apr 20, 2009 3:40 am |
|
|
There in none int64 for smaller PICs. int64 for 24H &dspic only. pito |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Apr 20, 2009 4:35 am |
|
|
You didn't tell your PIC. But you can port Microchip AN0617 fixed point assembly routines. |
|
|
piti2333 Guest
|
|
Posted: Mon Apr 20, 2009 5:09 am |
|
|
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 |
|
|
|