Truncated match.
PICList
Thread
'16C54 Programming Help?'
1998\09\10@175021
by
Steve Kasm
Hi All,
Here's another newbie question, please bear with me....
If a have a register loaded with data 
myreg == 00010111
what I would like to do is take the 4 least significant bits ie: bits
03 and do an xor on them. I then need to store the result in another
register to allow for a conditional branch afterwards.
My problem is : How do I perform the xor on only the first 4 bits. How
to store result.?
Any help Appreciated.
Thanks
Steve J. Kasm
spam_OUTkcerTakeThisOuTcgocable.net
1998\09\10@185119
by
Tony Nixon
Steve Kasm wrote:
>
> Hi All,
>
> Here's another newbie question, please bear with me....
movf myreg,w ; your data
andlw b'00001111' ; mask upper 4 bits
xorlw b'0000bbbb' ; XOR least significant bits
movwf Result ; store result
if result of XOR = 0 then Z will be set = 1

Best regards
Tony
Multimedia 16F84 Beginners PIC Tools.
**New Improved PicNPost**
http://www.picnpoke.com
Email .....picnpokeKILLspam@spam@cdi.com.au
1998\09\10@193051
by
paulb
Steve Kasm wrote:
> myreg == 00010111
> what I would like to do is take the 4 least significant bits ie: bits
> 03 and do an xor on them. I then need to store the result in another
> register to allow for a conditional branch afterwards.
> My problem is : How do I perform the xor on only the first 4 bits. How
> to store result.?
Tony Nixon's reply is noted. If however your question is that you
want an XOR on the LSN with the MSN unchanged, rather than zeroed, then
you need to mask the data with which you will XOR, first. But I'm
sure you can figure that out from Tony's post.

Cheers,
Paul B.
1998\09\10@194730
by
Dmitry Kiryashov
Paul B. Webster VK2BZC wrote:
>
> Steve Kasm wrote:
>
> > myreg == 00010111
>
> > what I would like to do is take the 4 least significant bits ie: bits
> > 03 and do an xor on them. I then need to store the result in another
> > register to allow for a conditional branch afterwards.
>
> > My problem is : How do I perform the xor on only the first 4 bits. How
> > to store result.?
>
> Tony Nixon's reply is noted. If however your question is that you
> want an XOR on the LSN with the MSN unchanged, rather than zeroed, then
> you need to mask the data with which you will XOR, first. But I'm
> sure you can figure that out from Tony's post.
> 
It seems to me that Steve only want to check LSN bits after
XORing it with some value. For this reason I think andlw
instruction is not needed, simply read original value then
xorlw it with bit_mask then save it to another register then
test bits in result register. MSN bits easy to ignore.
WBR Dmitry.
1998\09\10@233520
by
Steve Kasm

I might not have been clear in my first question... What I need to do is xor
the lsb together ie;;
Take the 4 least significant bits as individual bits. and xor together
b3 xor b2 xor b1 xor b0 == if result = 1 then do "branch"
branch elsewhere if result is zero
Is this what the example from Tony Nixon does or does it xor the bits with
some other value.?
Paul B. Webster VK2BZC wrote:
{Quote hidden}> Steve Kasm wrote:
>
> > myreg == 00010111
>
> > what I would like to do is take the 4 least significant bits ie: bits
> > 03 and do an xor on them. I then need to store the result in another
> > register to allow for a conditional branch afterwards.
>
> > My problem is : How do I perform the xor on only the first 4 bits. How
> > to store result.?
>
> Tony Nixon's reply is noted. If however your question is that you
> want an XOR on the LSN with the MSN unchanged, rather than zeroed, then
> you need to mask the data with which you will XOR, first. But I'm
> sure you can figure that out from Tony's post.
> 
> Cheers,
> Paul B.
1998\09\10@235445
by
Tony Nixon
Steve Kasm wrote:
>
> b3 xor b2 xor b1 xor b0 == if result = 1 then do "branch"
> branch elsewhere if result is zero
movf data,w
andlw b'00001111'
btfsc status,z
goto result=0 ; all 0's XOR to 0
xorlw b'00001111'
btfsc status,z
goto result=0 ; all 1's XOR to 0
goto result=1 ; any opposite bits XOR to 1
PS It's Friday, so I could be wrong ;)

Best regards
Tony
Multimedia 16F84 Beginners PIC Tools.
**New Improved PicNPost**
http://www.picnpoke.com
Email picnpokeKILLspamcdi.com.au
1998\09\11@035508
by
Dwayne Reid
>I might not have been clear in my first question... What I need to do is xor
>the lsb together ie;;
>
>Take the 4 least significant bits as individual bits. and xor together
>
>b3 xor b2 xor b1 xor b0 == if result = 1 then do "branch"
>branch elsewhere if result is zero
Hmm . . . Its very late and I could be out to lunch here, but how about:
clrc
btfsc myreg,3 ;delete this and next line if you don't want
setc ; b3 xor b0
rlf myreg,W
xorwf myreg,W
andlw b'00001111' ; branch based upon Z flag
Note: I haven't tried this and I may not even understand the question properly.
dwayne
Dwayne Reid <.....dwaynerKILLspam.....planet.eon.net>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(403) 4893199 voice (403) 4876397 fax
1998\09\11@095829
by
Peter L. Peres
; #3 ! untested. (but need one ? ;)
rrf INPUT, W
xorwf INPUT, F
rrf INPUT, W
xorwf INPUT, F
rrf INPUT, W
xorwf INPUT, F ; LSB = B3^B2^B1^B0
; optional laundry
movlw 1
andwf INPUT, F
Peter
1998\09\11@104137
by
Shahid Sheikh

Steve:
Depending on if instruction cycles is more precious or the saving program
space is more precious, you may want to implement a jump table. The XOR you
want to do has the following result. You can see have an odd number of 1's
yields an XOR of 1 and having an even number yields an XOR of 0.
0000 > 0
0001 > 1
0010 > 1
0011 > 0
0100 > 1
0101 > 0
0110 > 0
0111 > 1
1000 > 1
1001 > 0
1010 > 0
1011 > 1
1100 > 0
1101 > 1
1110 > 1
1111 > 0
So a code like
movf data
andlw b'00001111' ;Just keep b3b2b1b0
addwf PCL, w ;Add to PC for jump to appropriate line.
goto result=0
goto result=1
goto result=1
goto result=0
goto result=1
goto result=0
goto result=0
goto result=1
goto result=1
goto result=0
goto result=0
goto result=1
goto result=0
goto result=1
goto result=1
goto result=0
.
.
would do the job in 6 instruction cycles.
Another way to do something like this may be something like
btfsc data,3 ;Test b3. If b3==1 then complement data
cmpf
btfsc data,1 ;Test b1. If b1==1 then complement data
cmpf
btfss data,2 ;Test b2. If b2==1 then invert the testing sense
goto InvertLogic
btfss data,0 ;We know b2==0. Then if b0=0, XOR result=0
goto result=0 ;
goto result=1 ;if b0=1 then XOR result=1
InvertLogic
btfss data,0 ;We know b2==1. Then if b0=1, XOR result=1
goto result=1 ;
goto result=0 ;if b0=1 then XOR result=0
If you follow the table I made up top, you can see that the first 8 entries
has the same result as the complement of the last 8. Likewise the first 2
have the same result as the comp of the 2 following it. b3 being 1 or 0
just flip the XOR result.
I'm sure this is far from optimal but I think it would work. Actually, you
can make a combination of the jump table at the top and an algorimth that
uses the complement scheme and come up with something better.
I hope I didn't seriously goof this one up. I'm well known to do that.
Shahid

From: Steve Kasm[SMTP:EraseMEkcerspam_OUTTakeThisOuTCGOCABLE.NET]
Reply To: pic microcontroller discussion list
Sent: Friday, September 11, 1998 2:22 AM
To: PICLISTspam_OUTMITVMA.MIT.EDU
Subject: Re: 16C54 Programming Help?
I might not have been clear in my first question... What I need to do is
xor
the lsb together ie;;
Take the 4 least significant bits as individual bits. and xor together
b3 xor b2 xor b1 xor b0 == if result = 1 then do "branch"
branch elsewhere if result is zero
Is this what the example from Tony Nixon oes or does it xor the bits with
some other value.?
1998\09\11@112136
by
Shahid Sheikh

Ooops!! I made a booboo. When you take the complement the second time, it
will destroy the value of b2. I think the code that Peter posted is much
better.
Shahid

From: Shahid Sheikh[SMTP:@spam@sheikhKILLspamEROLS.COM]
Reply To: pic microcontroller discussion list
Sent: Friday, September 11, 1998 10:38 AM
To: KILLspamPICLISTKILLspamMITVMA.MIT.EDU
Subject: Re: 16C54 Programming Help?
Another way to do something like this may be something like
btfsc data,3 ;Test b3. If b3==1 then complement data
cmpf
btfsc data,1 ;Test b1. If b1==1 then complement data
cmpf
btfss data,2 ;Test b2. If b2==1 then invert the testing sense
goto InvertLogic
btfss data,0 ;We know b2==0. Then if b0=0, XOR result=0
goto result=0 ;
goto result=1 ;if b0=1 then XOR result=1
InvertLogic
btfss data,0 ;We know b2==1. Then if b0=1, XOR result=1
goto result=1 ;
goto result=0 ;if b0=1 then XOR result=0
If you follow the table I made up top, you can see that the first 8 entries
has the same result as the complement of the last 8. Likewise the first 2
have the same result as the comp of the 2 following it. b3 being 1 or 0
just flip the XOR result.
1998\09\11@122336
by
Scott Dattalo
Peter L. Peres wrote:
>
> ; #3 ! untested. (but need one ? ;)
> rrf INPUT, W
> xorwf INPUT, F
> rrf INPUT, W
> xorwf INPUT, F
> rrf INPUT, W
> xorwf INPUT, F ; LSB = B3^B2^B1^B0
>
> ; optional laundry
> movlw 1
> andwf INPUT, F
>
> Peter
how 'bout
rrf INPUT, W
xorwf INPUT, F
rrf INPUT, W
xorwf INPUT, F
rrf INPUT, W
xorwf INPUT, F ; LSB = B3^B2^B1^B0
; optional laundry
rrf INPUT, F ;(or W)
skpc
goto odd_parity
even_parity:
or (if we are destroying INPUT) a little faster:
rlf INPUT,w
xorwf INPUT,f
rlf INPUT,w
rrf INPUT,f
xorwf INPUT,f
btfsc INPUT,2
goto odd_parity
even_parity:
Scott
1998\09\11@171849
by
Dmitry Kiryashov
Scott Dattalo wrote:
> how 'bout
>
> rrf INPUT, W
> xorwf INPUT, F
> rrf INPUT, W
> xorwf INPUT, F
> rrf INPUT, W
> xorwf INPUT, F ; LSB = B3^B2^B1^B0
RRF INPUT,W
XORWF INPUT,F
BTFSC INPUT,2
DECF INPUT,F ; LSB = B3^B2^B1^B0
WBR Dmitry.
{Quote hidden}>
> ; optional laundry
> rrf INPUT, F ;(or W)
> skpc
> goto odd_parity
> even_parity:
>
> or (if we are destroying INPUT) a little faster:
>
> rlf INPUT,w
> xorwf INPUT,f
> rlf INPUT,w
> rrf INPUT,f
> xorwf INPUT,f
>
> btfsc INPUT,2
> goto odd_parity
>
> even_parity:
>
> Scott
1998\09\12@124530
by
Scott Dattalo
On Sat, 12 Sep 1998, Dmitry Kiryashov wrote:
>
> Scott Dattalo wrote:
>
> > how 'bout
> >
> > rrf INPUT, W
> > xorwf INPUT, F
> > rrf INPUT, W
> > xorwf INPUT, F
> > rrf INPUT, W
> > xorwf INPUT, F ; LSB = B3^B2^B1^B0
>
> RRF INPUT,W
> XORWF INPUT,F
> BTFSC INPUT,2
> DECF INPUT,F ; LSB = B3^B2^B1^B0
>
> WBR Dmitry.
which reminds me of Payson's solution for finding the parity on all 8
bits:
RRF INPUT,W
XORWF INPUT,F
SWAPF INPUT,W
XORWF INPUT,F
BTFSC INPUT,2
DECF INPUT,F ; LSB = B3^B2^B1^B0 ^ B7^B6^B5^B4
1998\09\14@050114
by
Stefan SczekallaWaldschmidt
Hi to all,
Shy: how is XOR for more than two bit defined ?
I know:
0 xor 0 = 0;
0 xor 1 = 1;
1 xor 0 = 1;
1 xor 1 = 0;
but what is with:
0 xor 1 xor 0 = ?
( and all other combinations ? )
is it handled like (a xor b) xor c ... ?
Had a look for a paritiygenerator schematic but it did4nt went into
details.
TIA
Stefan, confused :(
RemoveMEsswTakeThisOuToikossw.de
1998\09\14@100328
by
Mike Keitz

On Mon, 14 Sep 1998 11:01:51 +0100 Stefan SczekallaWaldschmidt
<spamBeGonesswspamBeGoneOIKOSSW.DE> writes:
>Hi to all,
>
>Shy: how is XOR for more than two bit defined ?
[...]
>is it handled like (a xor b) xor c ... ?
Yes. For 4 bits it is (a xor b) xor (c xor d), etc. It doesn't matter
what order the bits are xor'd in. ExclusiveORing is a lot like
addition.
>Had a look for a paritiygenerator schematic but it did4nt went into
>details.
The TTL parity generator (74XX280?) has a three level tree of 2input xor
gates that first xor the 8 inputs two at a time to a 4bit result, then
xors that to a 2 bit result, then xors those two together to the final
1bit result. The efficient PIC code I think due to Dmitry (at least the
final xor by testing bit 2 and complementing the result) works exactly
the same way.
_____________________________________________________________________
You don't need to buy Internet access to use free Internet email.
Get completely free email from Juno at http://www.juno.com
Or call Juno at (800) 654JUNO [6545866]
1998\09\14@174245
by
Dmitry Kiryashov
Scott Dattalo wrote:
> > RRF INPUT,W
> > XORWF INPUT,F
> > BTFSC INPUT,2
> > DECF INPUT,F ; LSB = B3^B2^B1^B0
> >
> which reminds me of Payson's solution for finding the parity on all 8
> bits:
>
> RRF INPUT,W
> XORWF INPUT,F
> SWAPF INPUT,W
> XORWF INPUT,F
> BTFSC INPUT,2
> DECF INPUT,F ; LSB = B3^B2^B1^B0 ^ B7^B6^B5^B4
Yes, I took in mind John's ideology. He was offer nice idea
of complementing last significant bit with decf/incf operation.
Decf operation is much pretty to incf because modification of
bits in INPUT register after decf will not exceed range of 2..0
bits while incf able to cause changing of INPUT byte entirely.
WBR Dmitry.
1998\09\15@124537
by
Peter L. Peres
On Tue, 15 Sep 1998, Dmitry Kiryashov wrote:
> > which reminds me of Payson's solution for finding the parity on all 8
> > bits:
snip
>
> Yes, I took in mind John's ideology. He was offer nice idea
> of complementing last significant bit with decf/incf operation.
> Decf operation is much pretty to incf because modification of
> bits in INPUT register after decf will not exceed range of 2..0
> bits while incf able to cause changing of INPUT byte entirely.
And it didn't remnid me of it because I haven't seen it...
Peter
More... (looser matching)
 Last day of these posts
 In 1998
, 1999 only
 Today
 New search...