# Re: Maths in assembly language.

Started by September 21, 2009
Hey,
Can anyone still explain how to divide two integers (not necessarily by a power of 2)?

Mishal
>
>
>
> Hi Rob,
>
>check DSP56800 Family's manual chapter 3.3.5.2 Integer Multiplication.
>There you will find that any multiplication is done in fractional
>format. To convert it back to integer you have to do following:
>
>MPY X0,Y0,A ; Generates correct answer shifted
>; 1 bit to the left
>ASR A ; Leaves Correct 32-bit Integer
>; Result in the A Accumulator
>; and the A2 register contains
>; correct sign extension
>
>Hopefully this helps.
>
>Jan
>
>
>On Sun, Nov 30, 2003 at 02:29:43PM -0000, dibosco wrote:
>> In an attempt to speed our (C) code up, I'm trying to have a go at
>> doing some maths in assembly language and getting some pretty bizarre
>> results.
>>
>> I'm trying to take baby steps and writing some noddy code to get me
>> familiar with the processor.
>>
>> The following code:
>>
>> move #5,Y0
>> move #2,X0
>> mpysu X0,Y0,A
>>
>> Bizarrely gives and answer of 20! In fact any multimplication for some
>> strange reason gives two times the answer you'd expect.
>>
>> Also, I've tried to do a divide. The div function seems not to be a
>> straight forward divide instruction, but some sort of interative
>> function. Does anyone undestand how it works and knows how to explain
>> its use in simple terms? I've tried to follow the text in the family
>> manual but am utterly lost.
>>
>> Many thanks.
>>
>> Rob.
>>
>>
Hi Mishal,

you need a four quadrant division to solve all four cases for different signs of divisor and divident. You will find it explained with code examples here:

www.chameleon.synth.net/files/developer/pdf/motorola/APR3.pdf

or a link to the archieved file here:

I have verified the fractional division codes to make sure they are working.

Best regards

Christian

> Hey,
> Can anyone still explain how to divide two integers (not necessarily by a
> power of 2)?
>
> Mishal
> >
> >
> >
> > Hi Rob,
> >
> >check DSP56800 Family's manual chapter 3.3.5.2 Integer Multiplication.
> >There you will find that any multiplication is done in fractional
> >format. To convert it back to integer you have to do following:
> >
> >MPY X0,Y0,A ; Generates correct answer shifted
> >; 1 bit to the left
> >ASR A ; Leaves Correct 32-bit Integer
> >; Result in the A Accumulator
> >; and the A2 register contains
> >; correct sign extension
> >
> >Hopefully this helps.
> >
> >Jan
> >
> >
> >On Sun, Nov 30, 2003 at 02:29:43PM -0000, dibosco wrote:
> >> In an attempt to speed our (C) code up, I'm trying to have a go at
> >> doing some maths in assembly language and getting some pretty bizarre
> >> results.
> >>
> >> I'm trying to take baby steps and writing some noddy code to get me
> >> familiar with the processor.
> >>
> >> The following code:
> >>
> >> move #5,Y0
> >> move #2,X0
> >> mpysu X0,Y0,A
> >>
> >> Bizarrely gives and answer of 20! In fact any multimplication for some
> >> strange reason gives two times the answer you'd expect.
> >>
> >> Also, I've tried to do a divide. The div function seems not to be a
> >> straight forward divide instruction, but some sort of interative
> >> function. Does anyone undestand how it works and knows how to explain
> >> its use in simple terms? I've tried to follow the text in the family
> >> manual but am utterly lost.
> >>
> >> Many thanks.
> >>
> >> Rob.
> >>
> >>