Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to do multiplication without using math operation ???

Status
Not open for further replies.

ecaits

Member level 4
Joined
Jan 16, 2014
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
579
Dear All,

How to do multiplication operation without using math library. I am using float datatype.

I am working on PIC16F877 using hi-tech C compiler.
I have read that multiplication in math operation consuming more program memory so I want to optimize my program code, if any other logic is available for multiplication....

Thank you in advance,

Nirav
 
Last edited:

I'm not sure whether you are aware of this logic.
Also i'm not sure whether this can save your program memory.

HTML:
int a;
int b;
int i = 0;
long sum = 0;

x = a; y = b;

if(x > y)	
{
	x = a;
	y = b;	
}

else 
{
	x = b;
	y = a;
}

for(i = 0; i < y; i++)
{
	sum = sum + x;
}

If i'm wrong, Please correct.
Hope it helps.
 

Dear Sir,

But I am using float datatype....
 

in general floating point operations take longer to carry out than integer in particular where processors do not have floating point coprocessors and use software to do the caluclations (also in such cases the code can be very large)

in general if reading integer data, e.g. from an ADC, keep it as integer data as long as possible.
if there is danger of exceeding the numeric limits of integer values there are alternatives to consider before converting to floating point
1. use unsigned integer types if there are no negative values
2. use long integer types
3. normalise the integer values so that numeric limits will not be exceeded in calculations
4. use processors with hardware suited to specific operations, e.g. DSP processors with built in support for FFTs, etc

if one has to use floating point and run out of program memory move to a processor with more memory
if floating point operations are too slow move to processor with a floating point coprocessor

also remember if one wants to multiply an integer by 2 one can shift left
Code:
x <<= 1;
or divide by 2 shift right
Code:
x>>1;
in the latter case be careful - some implementations may use logical shift rather than arithmetic shift so the sign bit becomes 0 - a problem when data may be negative
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top