[sdiy] help...no make8() function in Arduino...converting PIC to AVR
m.bareille at free.fr
m.bareille at free.fr
Wed Apr 11 19:35:22 CEST 2012
Hi Dan and List friends ,
-mul(x,y) is a simple multiplication i guess.
The multiplication is not implemented by default on 8 bits PIC chips ( serie
10,12,16) This function is present only on the 18,24,33 series.
If you want a good implementation of the mul/mult( )function for 8bits PIC , i
suggest you to read the Microchip application note #AN544 math utility routines.
It is well explained.
Indeed it is assembler only and a little bit subbtle because of the overload
management. It should not be very complex to translate it in C i think...
Good luck with you coding activies !
Cheers,
Marc B.
http://m.bareille.free.fr
PAPAREIL SYNTHLABS
Selon dan snazelle <subjectivity at hotmail.com>:
> more specifically
>
> in a macro
>
>
> #define _mul (int)( a1*val>>8)
>
>
> then when i go in and i do
>
>
> tmp2 = _mul (acc2, tmpamt);
>
> how does the define know that acc2=a1 and tmpampt=val??
>
> thanks
>
>
> On Apr 11, 2012, at 12:57 PM, Olivier Gillet wrote:
>
> > There's a cost associated to calling "proper" functions - parameters
> > being pushed to the stack or moved to the right register, then a jump,
> > the body of the function, a return, and moving the result from the
> > output register to whatever register the result should be in. You
> > don't want such small things to be functions - and that's probably why
> > they were defined as macros in the first place! So you either have to
> > define those as macro ; or as inline functions, using something like
> > __attribute__((always_inline)) in the declaration. gcc might be smart
> > enough to inline them without being forced to do so with the
> > __attribute__, but it's not a very good thing to make such
> > assumptions.
> >
> > Olivier
> >
> > On Wed, Apr 11, 2012 at 6:47 PM, dan snazelle <subjectivity at hotmail.com>
> wrote:
> >> ok so if
> >>
> >>
> >> make8 = (((var >> (offset*8)) & 0xff)
> >> _mul value = (int)( a1*val1>>8);
> >>
> >>
> >>
> >> then since i dont quite understand the parentheses in define I could make
> 2 functions
> >>
> >>
> >>
> >> byte make8(int var, byte offset)
> >> {
> >> byte result=(((var >> (offset*8)) & 0xff);
> >> return result;}
> >>
> >>
> >>
> >> and for the other function (_mul)
> >>
> >>
> >> int _mul (byte a1, byte val) {
> >>
> >> int result=(int)( a1*val1>>8);
> >> return result;
> >> }
> >>
> >>
> >>
> >> do those look right?
> >>
> >>
> >> thanks
> >>
> >>
> >>
> >>
> >>
> >> On Apr 11, 2012, at 12:00 PM, Martin Klang wrote:
> >>
> >>>
> >>> what do they do on the pic?
> >>>
> >>> make8 I found in the PIC C Compiler Reference:
> >>> i8 = MAKE8(var, offset)
> >>> Same as: i8 = (((var >> (offset*8)) & 0xff)
> >>>
> >>> so that
> >>>> tmpbyte1 = make8(tmp1, 1);
> >>>
> >>> would be
> >>> tmpbyte1 = (tmp1 >> 8) & 0xff;
> >>>
> >>> and _mul() multiplies, right?
> >>>
> >>> Looks like the code is specifically optimised for the pic instructions
> set -
> >>> tmp1 is 16 bit, right? acc1 and val1 8-bit unsigned integers?
> >>>
> >>> Presumably you can replace the two lines with
> >>> uint8_t value = (uint8_t)( acc1*val1>>8);
> >>> depending on data types, but would have to see some more code to know.
> >>>
> >>>
> >>> hth,
> >>>
> >>> /m
> >>>
> >>> On 11 Apr 2012, at 16:25, dan snazelle wrote:
> >>>
> >>>> can someone help me ?
> >>>>
> >>>> i am trying to convert some PIC code to AVR
> >>>>
> >>>> it is going fine except for 2 things
> >>>>
> >>>> there is no make8() function and there is no _mul()
> >>>>
> >>>>
> >>>> so code lines like this:
> >>>>
> >>>>
> >>>> tmp1 = _mul (acc1, val1);
> >>>>
> >>>> tmpbyte1 = make8(tmp1, 1);
> >>>>
> >>>>
> >>>> do not work
> >>>>
> >>>>
> >>>>
> >>>> i have been looking for the make8 function online so i can just write
> that function into my code but no luck
> >>>>
> >>>>
> >>>> thanks for any help!
> >>>
> >>>
> >>
> >> _______________________________________________
> >> Synth-diy mailing list
> >> Synth-diy at dropmix.xs4all.nl
> >> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
> >
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>
More information about the Synth-diy
mailing list