Cast one or both operands to 32-bit and C will give you a 32 bit result. Or copy one to a 32-bit and use that as the result.

No assembly required.

Sincerely,

David Smead
www.amplepower.com
www.amplepower.net


On Tue, 22 Apr 2008, Przemek Klosowski wrote:

On Mon, Apr 21, 2008 at 2:42 PM, Christian Böhme <[email protected]> wrote:

> you need to read the compiler code generation templates (tricky).

 What's so tricky about that ?

Code generation templates are provided in Machine Description files,
like those two for gcc 3.2.3 and 4.1.1:

http://mspgcc.cvs.sourceforge.net/mspgcc/gcc/gcc-4.1.1/gcc/config/msp430/msp430.md?revision=1.2&view=markup
http://mspgcc.cvs.sourceforge.net/mspgcc/gcc/gcc-current/gcc/config/msp430/msp430.md?revision=1.2&view=markup

I find them obtuse and tricky, and I am relieved to hear you disagree,
because the answer to your question
is in the .md file that the MPY-capable version of mspgcc uses. I
haven't run into the MPY issues before, so
I don't even know which gcc versions can use it---I haven't found the
relevant MD templates in the files I looked at.

In general, however, you are right that in standard ANSI C the
multiply result size is determined by the operands, resulting in
truncation. In that case, you may need to use inline assembly to
accomplish your 16x16->32  operation. Again, I haven't used MUL so the
example below is just supposed to give you a general idea
and is almost certainly wrong for generating the MPY instruction on msp430

asm ("MPY %1,%0" : "=r" (result) : "r" (op1),"r"(op2))

Brennan's inline assembly tutorial for x86 is at
http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html;
I don't know of a good explanation of operand descriptors for MSP
inline assembly.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to