EmbeddedRelated.com
Forums

floating point calculations.

Started by knightslancer February 10, 2009
Hi Friends,

I have tried a lot about this. I donno if my mind is not good at this.

I am trying to do an arithmetic calculations that involve multiplying a 32
bit integer with a floating point numbers. For example:

200 * 5.25.

How can I write an assembly code for this on ARM7 LPC2292 boards. Please
help me out with this. I am a started in assembly language programming.

Thanks
knight


knightslancer schrieb:
> Hi Friends, > > I have tried a lot about this. I donno if my mind is not good at this. > > I am trying to do an arithmetic calculations that involve multiplying a 32 > bit integer with a floating point numbers. For example: > > 200 * 5.25.
= 200 * 21 / 4 It's fastest if you can reduce your problem to integer operations. Please check if you _really_ need floating point operations. -- Mit freundlichen Gr��en Dipl.-Ing. Frank-Christian Kr�gel
On Feb 10, 10:43=A0am, "knightslancer" <knightslan...@gmail.com> wrote:
> Hi Friends, > > I have tried a lot about this. I donno if my mind is not good at this. > > I am trying to do an arithmetic calculations that involve multiplying a 3=
2
> bit integer with a floating point numbers. For example: > > 200 * 5.25. > > How can I write an assembly code for this on ARM7 LPC2292 boards. Please > help me out with this. I am a started in assembly language programming. > > Thanks > knight
do it in C and look at the asembly output
On Tue, 10 Feb 2009 16:59:00 +0100, Frank-Christian Kr&uuml;gel wrote:

> knightslancer schrieb: >> Hi Friends, >> >> I have tried a lot about this. I donno if my mind is not good at this. >> >> I am trying to do an arithmetic calculations that involve multiplying a >> 32 bit integer with a floating point numbers. For example: >> >> 200 * 5.25. > > = 200 * 21 / 4 > > It's fastest if you can reduce your problem to integer operations. > Please check if you _really_ need floating point operations.
200 * 21 Right shift the answer by 2. (remember, this is assembly...) -- http://www.wescottdesign.com
On Tue, 10 Feb 2009 09:43:53 -0600, knightslancer wrote:

> Hi Friends, > > I have tried a lot about this. I donno if my mind is not good at this. > > I am trying to do an arithmetic calculations that involve multiplying a > 32 bit integer with a floating point numbers. For example: > > 200 * 5.25. > > How can I write an assembly code for this on ARM7 LPC2292 boards. Please > help me out with this. I am a started in assembly language programming. > > Thanks > knight
Either the chip has floating point hardware or it doesn't. If it does have floating point hardware, then you need to figure out how to use it (and if you have to be told, in detail, how to do it for this chip, then assembly language programming isn't for you). Most of the FP hardware that I've seen involves an engine that's sorta kinda separate from the chip's regular ALU. You'll need to load some special floating point registers with the numbers, then call a special floating point instruction* and do whatever you need to do to retrieve the result. Note that floating point hardware is often quite loosely coupled to the rest of the processor, which can cause synchronization problems if you're not careful. If your assembly is coexisting with C, and if the hardware isn't tightly coupled, you may screw up the C floating point library's state machine by twiddling with the processor's floating point hardware -- I have _absolutely no idea_ how the ARM handles this particular task, so I can't say if this is an issue or not. If it doesn't have floating point hardware then it's up to software to provide floating point operations. If you're lucky you'll have access to a floating point library (often these will be called "emulation" libraries), and you'll just have to figure out how to use it. If you're _not_ lucky you'll have to write your floating point library. I would expect that there's _something_ floating around out there in Gnu-land for software floating point for the ARM, but you'll have to find it. * I don't think this applies to ARM chips in general, but for less well integrated processors there may be no separate "floating point" instructions. Instead, you have to actually tickle the floating point hardware somehow (sometimes the write of the second operand will do it), and poll the hardware (or get interrupted) to see that it's done. -- http://www.wescottdesign.com
>On Feb 10, 10:43=A0am, "knightslancer" <knightslan...@gmail.com> wrote: >> Hi Friends, >> >> I have tried a lot about this. I donno if my mind is not good at this. >> >> I am trying to do an arithmetic calculations that involve multiplying a
3=
>2 >> bit integer with a floating point numbers. For example: >> >> 200 * 5.25. >> >> How can I write an assembly code for this on ARM7 LPC2292 boards.
Please
>> help me out with this. I am a started in assembly language
programming.
>> >> Thanks >> knight > >do it in C and look at the asembly output >
Hey guys thanks for your posts. But, I had to represent data in Q24.8 format and integer in 32 bit format. using DCD directives only in the data section as like: x DCD 100 a DCD 525E-2 Only after doing this I had to manipulate to make room for the calculations. Please help me. Thanks knight
On Tue, 10 Feb 2009 11:42:10 -0600, knightslancer wrote:

>>On Feb 10, 10:43=A0am, "knightslancer" <knightslan...@gmail.com> wrote: >>> Hi Friends, >>> >>> I have tried a lot about this. I donno if my mind is not good at this. >>> >>> I am trying to do an arithmetic calculations that involve multiplying >>> a > 3= >>2 >>> bit integer with a floating point numbers. For example: >>> >>> 200 * 5.25. >>> >>> How can I write an assembly code for this on ARM7 LPC2292 boards. > Please >>> help me out with this. I am a started in assembly language > programming. >>> >>> Thanks >>> knight >> >>do it in C and look at the asembly output >> >> > Hey guys thanks for your posts. But, I had to represent data in Q24.8 > format
Then it's not floating point! Say what you mean.
> and integer in 32 bit format. using DCD directives only in the > data section as like: > > x DCD 100 > a DCD 525E-2 > > Only after doing this I had to manipulate to make room for the > calculations. Please help me. > > Thanks > knight
"Using only DCD directives" That can only be homework. What did your professor say? -- http://www.wescottdesign.com
>On Tue, 10 Feb 2009 11:42:10 -0600, knightslancer wrote: > >>>On Feb 10, 10:43=A0am, "knightslancer" <knightslan...@gmail.com>
wrote:
>>>> Hi Friends, >>>> >>>> I have tried a lot about this. I donno if my mind is not good at
this.
>>>> >>>> I am trying to do an arithmetic calculations that involve
multiplying
>>>> a >> 3= >>>2 >>>> bit integer with a floating point numbers. For example: >>>> >>>> 200 * 5.25. >>>> >>>> How can I write an assembly code for this on ARM7 LPC2292 boards. >> Please >>>> help me out with this. I am a started in assembly language >> programming. >>>> >>>> Thanks >>>> knight >>> >>>do it in C and look at the asembly output >>> >>> >> Hey guys thanks for your posts. But, I had to represent data in Q24.8 >> format > >Then it's not floating point! Say what you mean. > >> and integer in 32 bit format. using DCD directives only in the >> data section as like: >> >> x DCD 100 >> a DCD 525E-2 >> >> Only after doing this I had to manipulate to make room for the >> calculations. Please help me. >> >> Thanks >> knight > >"Using only DCD directives" That can only be homework. What did your >professor say? > >-- >http://www.wescottdesign.com >
Humm... then what can be the best way to do it ?
On Tue, 10 Feb 2009 09:43:53 -0600, "knightslancer"
<knightslancer@gmail.com> wrote:

>Hi Friends, > >I have tried a lot about this. I donno if my mind is not good at this. > >I am trying to do an arithmetic calculations that involve multiplying a 32 >bit integer with a floating point numbers. For example: > >200 * 5.25. > >How can I write an assembly code for this on ARM7 LPC2292 boards. Please >help me out with this. I am a started in assembly language programming.
If the processor does not have a floating point instruction set, just convert the integer to the same floating point notation as your floating point numbers (whatever notation you have chosen). Doing the actual floating point multiplication is just multiplying the significands and adding the exponents and correcting the bias. But as others have said, the best thing in most embedded systems is getting rid of the floating point calculations entirely. Paul

Paul Keinanen wrote:


> But as others have said, the best thing in most embedded systems is > getting rid of the floating point calculations entirely.
I have to disagree here. Although the floating point math is typically somewhat 15 times slower then the native math of 8/16 bitter, it greatly simplifies the development and makes the code much more readable and portable. As for the code speed and size, it matters only in the few cases when it matters. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com