Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to compare two bits in the same byte using ASM?

Status
Not open for further replies.

JohnJohn20

Advanced Member level 4
Joined
Feb 2, 2012
Messages
111
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,377
Hi. Is there a quick way to XOR two bits in a byte? If they are the same then do something else do something else.

I can do this using btfsc and btfss but it takes many lines of code.

Thanks.
 

Hi,

ASM commands / instruction set depends on microcontroller type.
--> you should give us this information.

Klaus
 

Both the BTFSC and BTFSS instructions are supposed from the midrange Microchip's PIC familly.
Anyway, when it is said "many lines of code" don't necessarily means as being not a fast implementation.
You could think about put all the 4 possible results in a lookup table by using the RETLW instruction.
 

The fastest if the source byte is disposable and the two bits are adjacent:
Code:
 rlf source , w ; put bit1 in the same position in w
 xorwf source , f ;compare bits
 btfss source,bit2 ; branch 
 goto option1
option2; different
option1 ; equal
source byte not disposable
Code:
 rlf source , w 
 xorwf source , w
 andlw 2^bit2 ; keep  the result in w
 btfss status,z 
 goto option1
option2; different
option1 ; equal
two bytes in random position , source byte not disposable
Code:
 movf source,w
 btfsc source bit1 
 comf source, w ; complement if bit1 is 1
 andlw 2^bit2 
 btfss status,z 
 goto option1
option2 ; different
option1 ; equal

two bytes in random position , source byte disposable
Code:
 btfsc source bit1 
 comf source, f ; complement if bit1 is 1
 btfss source, bit2
 goto option2
option1 ; different
option2 ; equal
 
Sorry Klaus, that is true. And Andre, it is a 16F88 as you guessed right.

It takes perhaps 16 lines of code and speed is not really a factor.

I was just looking for a tidier way of doing it. It is a lot simpler to compare two bytes than two bits.

And mdorian, I like your bits of code (no pun intended). I will adapt them. Thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top