EmbeddedRelated.com
Forums

Multiplier madness ...................... help

Started by jkw_ee September 18, 2008
jkw_ee wrote:
> I have started digging into how the multiplies are implemented in my
> software.
>
> MSP4301611
> IAR 3.42A (should update soon)
>
> I am multiplying two signed integers (16bit signed)

Hi Jkw!

Looks like I'm the last to jump on the band wagon on this one, so I just
try to keep this short.

What you just ran into is the classical "16 bit int" problem In C. The
language standard states that if an operation is applied to two "int":s
the result is also an "int".

In you case you have:

a_long = an_int * another_int;

This is the same thing as:

a_long = (long)(an_int * another_int);

(The assembler instructions doing "RLA" etc. is part of the sign extend
form "int" to "long".)

As a number of people already have pointed out, you need to cast at
least one of the operands to "long" to get a 16*16=>32 multiplication:

a_long = ((long)an_int) * another_int;

Hope this shed some lights on your problem.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Beginning Microcontrollers with the MSP430

There is a wonderful program that looks through your code and warns you
of little things like this. Its called LINT. It will scour the code
looking for stuff that doesn't match exactly. Kind of a code checker on
steroids. It takes a little time initially, to tame the program and
understand it. Once done, it is highly valuable.

Dan

________________________________

From: m... [mailto:m...] On Behalf
Of Anders Lindgren
Sent: Friday, September 19, 2008 4:56 AM
To: m...
Subject: Re: [msp430] Multiplier madness ...................... help

jkw_ee wrote:
> I have started digging into how the multiplies are implemented in my
> software.
>
> MSP4301611
> IAR 3.42A (should update soon)
>
> I am multiplying two signed integers (16bit signed)

Hi Jkw!

Looks like I'm the last to jump on the band wagon on this one, so I just

try to keep this short.

What you just ran into is the classical "16 bit int" problem In C. The
language standard states that if an operation is applied to two "int":s
the result is also an "int".

In you case you have:

a_long = an_int * another_int;

This is the same thing as:

a_long = (long)(an_int * another_int);

(The assembler instructions doing "RLA" etc. is part of the sign extend
form "int" to "long".)

As a number of people already have pointed out, you need to cast at
least one of the operands to "long" to get a 16*16=>32 multiplication:

a_long = ((long)an_int) * another_int;

Hope this shed some lights on your problem.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.


--- In m..., Dan Bloomquist wrote:
>
> swarf_maker wrote:
> > There is a better way and it is called Forth.
> >
>
> Wow! A blast from the past!

It is still current. You can get cross-tools for the more popular
micros as well as resident Forth for the PC/Win from both Forth Inc.
in the US and MPE in the UK. There are also free versions available
for the PC. Win32Forth is an example.

> I wrote a Forth compiler, interpreter, that blew 'Capitan Forth'
away on
> the Apple One. It was that intrinsic characteristic of not being
able to
> indirect jump on page boundaries. Instead of a double jump
involving a
> copy address, I let the compiler handle it. My code was fast.
>
> Fast forward, I would not write in anything but C++ if I can help
it.
> Well, PHP is nice for the web. Now fast is hardly a consideration
but at
> the abstract level on a box.
>

My preference for Forth is not for its speed but for its
interactivity. I write a (usually) small function and than test it.
Overall, I spend a lot more time testing and a lot less time
debugging than I ever did with C. Also, a lot of the questions asked
here relating to how to make the hardware work could be easily
resolved in an interactive environment with data sheet in hand.

Datasheets are never an easy read and there are clearly many here for
whom English is not their first language. An interactive development
environment might help them too.

> Ease of use, I guess Forth is ok at the forklift level. But C is so
> natural, and after all, a primitive language. What more could you
want???
>

I guess it all depends on what you are comfortable with. I have
written thousands of lines of C/C++ under Windows. I'm not sure I
would undertake a large PC based project in Forth (there are those
who have done so) but for embedded applications, I wouldn't even
consider C where Forth is an option.

I don't get your forklift reference, but as far as C being natural I
would be hard to convinvce on that point. For me, C has too many
rules constraints and subtleties that were always tripping me up. The
recent problem posted by Mike Raines (#38316) is an excellent case in
point.

To reiterate, it all depends on what you are comfortable with. I see
here a lot of people having difficulties with C and with getting
hardware abstraction code working. For them Forth might be a better
alternative. But it appears from this MB that most aren't even aware
of Forth's existence, much less its availability for the MSP430
family.

Bob
> Best, Dan.
> --
> email: yotox@... but drop the 'x'.
>

--- In m..., Onestone wrote:
>
> Good grief don't be so serious! From someone who has programmed in
most
> languages, including FORTH (jupiter Ace and various small hand
helds),
> on machines ranging from dual main frames through home made RTL based
> machines, bit slicers and even Block NORPAK (if anybody has even
heard
> of that stuff!) to Steve Ciarcia's favourite (he who founded Circuit
> cellar), who regularly stated "My favourite programming language is
> solder". I just like to stir the shitoccasionally. It's good for the
soul.
>
> Al

A hardware person at heart, my favorite programming language is also
solder, but at 64 these 0.5 mm lead-pitch parts are a challenge.

NORPAK? The Ottawa company that was pushing Teletext way back when?
----- Original Message -----
From: "swarf_maker"
To:
Sent: Friday, September 19, 2008 3:22 PM
Subject: [msp430] Re: Multiplier madness ...................... help
> --- In m..., Dan Bloomquist wrote:
>>
>> swarf_maker wrote:
>> > There is a better way and it is called Forth.
>> >
>>
>> Wow! A blast from the past!
>
> It is still current. You can get cross-tools for the more popular
> micros as well as resident Forth for the PC/Win from both Forth Inc.
> in the US and MPE in the UK. There are also free versions available
> for the PC. Win32Forth is an example.

Sun used Forth for the I/O drivers on their SPARC systems, perhaps they
still do. It was even possible to boot a Sun machine into a Forth
interpreter. I remember trying it once.

Leon
--- In m..., Onestone wrote:
>
> I guess thats kind of intuitive, if you are at one with the BORG
>
> Al

Intuitive is Pacman. There isn't a manual, you don't need one. There
are no intuitive programming languages. They all require manuals that
sell for $40.00 and up in mafia run university bookstores.

Keep on stirring that stuff.

Bob
Hardware raised, software dedicated. I love my code! The two are like
sausage and mash, or fish and Chips, one is not the same without the other!

Block NORPAK was an old Square D thing. House Brick sized boxes each
with a different logic function. Most had more than 1 gate type per
brick. each gate sat on its own insulated brass strip, and you patch
wired the gates to build circuits. basic unit was NOR gate, hence the
name. There were also OR, delay, potentiometer, single bit memory (ie
latches) that I can remember. weirdly enough used extensively in control
systems around Oil refineries. especially in Cat regen towers. I met
this stuff in the early 80's.

Cheers

Al

swarf_maker wrote:

>--- In m..., Onestone wrote:
>
>
>>Good grief don't be so serious! From someone who has programmed in
>>
>>
>most
>
>
>>languages, including FORTH (jupiter Ace and various small hand
>>
>>
>helds),
>
>
>>on machines ranging from dual main frames through home made RTL based
>>machines, bit slicers and even Block NORPAK (if anybody has even
>>
>>
>heard
>
>
>>of that stuff!) to Steve Ciarcia's favourite (he who founded Circuit
>>cellar), who regularly stated "My favourite programming language is
>>solder". I just like to stir the shitoccasionally. It's good for the
>>
>>
>soul.
>
>
>>Al
>>
>>A hardware person at heart, my favorite programming language is also
>solder, but at 64 these 0.5 mm lead-pitch parts are a challenge.
>
>NORPAK? The Ottawa company that was pushing Teletext way back when?
>
I've never paid for a programming manual, although I've known a few
progammers who were called Manuel. University Book stores? Wouldn't
know, I got thrown off Flinders University Grounds for going around
spray painting '??' everywhere I saw the name "FLINDERS UNIVERSITY
CAMP?US?".

Pacman? Intuitive? How so, I mean I thought the idea behind PONG was to
teach HEX. Watching that little blob slide off screen, beep ferociously
and count from 0 to 15 gave me this inate understanding of HEX. Don't
tell me there was more to it than that!! What have I missed out on? Is
there no going back?

Al

swarf_maker wrote:

>--- In m..., Onestone wrote:
>
>
>>I guess thats kind of intuitive, if you are at one with the BORG
>>
>>Al
>>
>>Intuitive is Pacman. There isn't a manual, you don't need one. There
>are no intuitive programming languages. They all require manuals that
>sell for $40.00 and up in mafia run university bookstores.
>
>Keep on stirring that stuff.
>
>Bob
>
There may be going back: I just heard this morning of an arcade called
1984. It has many of the old electronic arcade games (Pac Man, Ms. Pac
Man, Asteroids, Space Invaders, etc.) and some pin ball machines. A $5
cover charge gives unlimited playing on all games. The bathrooms are
illuminated with blacklight.

The business claims to be the only one like it.

Emmett Redd Ph.D. mailto:E...@missouristate.edu
Professor (417)836-5221
Department of Physics, Astronomy, and Materials Science
Missouri State University Fax (417)836-6226
901 SOUTH NATIONAL Dept (417)836-5131
SPRINGFIELD, MO 65897 USA

Physicists always practice energy conservation.

> -----Original Message-----
> From: m... [mailto:m...]
> On Behalf Of Onestone
> Sent: Friday, September 19, 2008 10:55 AM
> To: m...
> Subject: Re: [msp430] Re: Multiplier madness
> ...................... help
>
> I've never paid for a programming manual, although I've known a few
> progammers who were called Manuel. University Book stores? Wouldn't
> know, I got thrown off Flinders University Grounds for going around
> spray painting '??' everywhere I saw the name "FLINDERS UNIVERSITY
> CAMP?US?".
>
> Pacman? Intuitive? How so, I mean I thought the idea behind
> PONG was to
> teach HEX. Watching that little blob slide off screen, beep
> ferociously
> and count from 0 to 15 gave me this inate understanding of HEX. Don't
> tell me there was more to it than that!! What have I missed
> out on? Is
> there no going back?
>
> Al
>
> swarf_maker wrote:
>
> >--- In m..., Onestone wrote:
> >
> >
> >>I guess thats kind of intuitive, if you are at one with the BORG
> >>
> >>Al
> >>
> >>
> >
> >Intuitive is Pacman. There isn't a manual, you don't need
> one. There
> >are no intuitive programming languages. They all require
> manuals that
> >sell for $40.00 and up in mafia run university bookstores.
> >
> >Keep on stirring that stuff.
> >
> >Bob
> >
> >
> >
> >
> >
> >
> >
A local all you can eat joint called CHARLIES DINER has a games room for
the kids with old Space invaders, Galaga and I think Pacman machines.
Again the old sit donw table top type. They're free to play. But the
only blacklight is when somebody smashes the bulbs. Not nice if you wear
thongs.

Al

Redd, Emmett R wrote:

>There may be going back: I just heard this morning of an arcade called
>1984. It has many of the old electronic arcade games (Pac Man, Ms. Pac
>Man, Asteroids, Space Invaders, etc.) and some pin ball machines. A $5
>cover charge gives unlimited playing on all games. The bathrooms are
>illuminated with blacklight.
>
>The business claims to be the only one like it.
>
>Emmett Redd Ph.D. mailto:E...@missouristate.edu
>Professor (417)836-5221
>Department of Physics, Astronomy, and Materials Science
>Missouri State University Fax (417)836-6226
>901 SOUTH NATIONAL Dept (417)836-5131
>SPRINGFIELD, MO 65897 USA
>
>Physicists always practice energy conservation.
>
>
>>-----Original Message-----
>>From: m... [mailto:m...]
>>On Behalf Of Onestone
>>Sent: Friday, September 19, 2008 10:55 AM
>>To: m...
>>Subject: Re: [msp430] Re: Multiplier madness
>>...................... help
>>
>>I've never paid for a programming manual, although I've known a few
>>progammers who were called Manuel. University Book stores? Wouldn't
>>know, I got thrown off Flinders University Grounds for going around
>>spray painting '??' everywhere I saw the name "FLINDERS UNIVERSITY
>>CAMP?US?".
>>
>>Pacman? Intuitive? How so, I mean I thought the idea behind
>>PONG was to
>>teach HEX. Watching that little blob slide off screen, beep
>>ferociously
>>and count from 0 to 15 gave me this inate understanding of HEX. Don't
>>tell me there was more to it than that!! What have I missed
>>out on? Is
>>there no going back?
>>
>>Al
>>
>>swarf_maker wrote:
>>
>>
>>
>>>--- In m..., Onestone wrote:
>>>
>>>
>>>
>>>
>>>>I guess thats kind of intuitive, if you are at one with the BORG
>>>>
>>>>Al
>>>>
>>>>
>>>>
>>>>
>>>Intuitive is Pacman. There isn't a manual, you don't need
>>>
>>>
>>one. There
>>
>>
>>>are no intuitive programming languages. They all require
>>>
>>>
>>manuals that
>>
>>
>>>sell for $40.00 and up in mafia run university bookstores.
>>>
>>>Keep on stirring that stuff.
>>>
>>>Bob
>>>
>>>
>>>
>>>
>>>
>>>
>>>