> Harry H. Arends wrote:
> > It does but it may be reducing the amount memory used.
> > And using more CV's easier.
>
> I'm not sure that the macro solution sugested by
> Olin would save any code space, it mainly makes
> the code a bit more readable, but as I understand
> it, the expanded macro would take more or less
> the same code space as before.
>
> Jan-Erik.
>
>
>
> >
> >> -----Oorspronkelijk bericht-----
> >> Van:
TakeThisOuTpiclist-bouncesKILLspam
spammit.edu [
.....piclist-bounces
RemoveMEmit.edu]
> >> Namens Jan-Erik Soderholm
> >> Verzonden: woensdag 7 januari 2009 11:17
> >> Aan: Microcontroller discussion list - Public.
> >> Onderwerp: Re: [PIC] xorlw question
> >>
> >> Harry H. Arends wrote:
> >>> I wil give it a try with youre solution. Thanks
> >>>
> >> Why ? Doesn't the original code work ?
> >>
> >>
> >>
> >>> Harry
> >>>
> >>>> -----Oorspronkelijk bericht-----
> >>>> Van:
RemoveMEpiclist-bounces
spamBeGonemit.edu
> >> [
spamBeGonepiclist-bounces@spam@
spam_OUTmit.edu] Namens
> >>>> Olin Lathrop
> >>>> Verzonden: woensdag 7 januari 2009 0:08
> >>>> Aan: Microcontroller discussion list - Public.
> >>>> Onderwerp: Re: [PIC] xorlw question
> >>>>
> >>>> Harry H. Arends wrote:
> >>>>> xorlw (0x08 ^ 0x1C) ; CV541
> >>>>> btfsc STATUS,Z
> >>>>> retlw CVAR_29
> >>>>> xorlw (0x1C ^ 0x02) ; CV515
> >>>>> btfsc STATUS,Z
> >>>>> retlw MAX_BRIGHT
> >>>> What's happening here is that he is testing the original
> >> value in W
> >>>> against a succession of constants. He checks for a particular
> >>>> constant by XORing it into W, then checking for the result
> >> being 0.
> >>>> That works, but corrupts the value in W.
> >>>> He therefore XORs the test value again into W, which
> >> restores W to
> >>>> its original value, then he XORs the new test value into W
> >> to be able
> >>>> to check for zero again.
> >>>>
> >>>> The optimization is to note that XORing with two
> >> successive values is
> >>>> the same as XORing with the XOR of the two values.
> >>>> Therefore XORing with the previous test value to restore W then
> >>>> XORing with the new test value is done in one step. He
> >> wrote out the
> >>>> two values separately and let the assembler find the XOR
> >> of them to
> >>>> make it easier to see what's going on.
> >>>>
> >>>> This is not very good programming because each test value
> >> is now in
> >>>> two places, leaving open the possibility of making a mistake and
> >>>> getting them out of sync. If I were to use this successive XOR
> >>>> technique, I would make a macro you pass the test value and the
> >>>> associated return value to. The macro would use a assembly time
> >>>> variable to track the previous test value and compute the new
> >>>> combined XOR value. The result would be easier to read and more
> >>>> maintainable, and you know that the previous value is always
> > XORed
> >>>> out correctly. The equivalent code to the snippet above
> >> would look
> >>>> something
> >>>> like:
> >>>>
> >>>> check_val h'1C', cvar_29 ;CV541
> >>>> check_val h'02', max_bright ;CV515
> >>>>
> >>>>
> >>>>
> >> ********************************************************************
> >>>> Embed Inc, Littleton Massachusetts,
> >>
http://www.embedinc.com/products
> >>>> (978) 742-9014. Gold level PIC consultants since 2000.
> >>>> --