Searching \ for 'Oring bits within a byte' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=oring+bits+within
Search entire site for: 'Oring bits within a byte'.

Truncated match.
'Oring bits within a byte'
1998\01\26@110958 by

Good morning -

I'm trying to do the following:

I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
together 3 of the bits within the byte.

ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)

There doesn't seem to be any bit wise 'or' functions. Any ideas on how
to implement this?

Daniel Najemy -  Data General Corporation, Numaliine Power Systems
Najemy, Daniel wrote:
>
> I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
> together 3 of the bits within the byte.
>
> ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)
>
> Any ideas on how to implement this?

bcf     nResultByte, bResultBit ; assume result bit is zero
movf    nTemp,W
andlw   (1<<3 + 1<<4 + 1<< 5)   ; w := 00xyz0000
btfss   STATUS,Z
bsf     nResultByte, bResultBit ; sets result bit

I think this should do it.
If all the bits 3, 4 and 5 are zero, W := z,
the zero flag is set and the result bit is not
On Mon, 26 Jan 1998 11:04:59 -0500 "Najemy, Daniel"
<DNajemyIMPS0014.US.DG.COM> writes:
>Good morning -
>
>I'm trying to do the following:
>
>I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
>together 3 of the bits within the byte.
>
>ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)
>

movlw   b'0011100'      ; Set up the mask
andwf   temp,0          ; Leave selected bits in w,
others 0
bz      AllZeroes               ; go deal with them all being
zeroes
...                     ; Code to be executed if one or more
bits were set

Harold

_____________________________________________________________________
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]
Mask the three bits using AND. Test if resultant byte is 0 or greater than 0. If
it is greater than 0, then the result should be set to 1.

Kieran

----------
From:   Najemy, Daniel[SMTP:DNajemyIMPS0014.US.DG.COM]
Sent:   26 January 1998 16:04
To:     PICLISTMITVMA.MIT.EDU
Subject:        Oring bits within a byte

Good morning -

I'm trying to do the following:

I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
together 3 of the bits within the byte.

ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)

There doesn't seem to be any bit wise 'or' functions. Any ideas on how
to implement this?

Daniel Najemy -  Data General Corporation, Numaliine Power Systems
Najemy, Daniel wrote:
>
> Good morning -
>
> I'm trying to do the following:
>
> I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
> together 3 of the bits within the byte.
>
> ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)
>
> There doesn't seem to be any bit wise 'or' functions. Any ideas on how
> to implement this?

Yeah, we had this discussion a few months back.

Using the nomenclature then, here's a way to or two arbitrary bits in
two aribtrary registers and place the result in another arbitray
register: e.g. C.bit_C = A.bit_a | B.bit_b:

BCF     C,bit_c
BTFSS  A,bit_a
BTFSC B,bit_b
BSF  C,bit_c

Which could be extended for three or more bits.

However in your case, there's even a simpler trick:

CLRF   RESULT        ;Assume all three bits are low

MOVF   TEMP,W
ANDLW  (1<<3) | (1<<4) | (1<<5)
SKPZ
INCF  RESULT        ;At least one bit was high

Scott
--
__o
(*)/(*)
Daniel,

Best I can do of the top of my head is:-

RLF     TEMP, W
IORWF   TEMP, F
RLF     TEMP, W
IORWF   TEMP, F

OR'ed result in TEMP,5
Trashes TEMP and W
4 cycles

I'm sure somebody can do it better

Steve Lawther

Subject:      Oring bits within a byte
Author:  PC:DNajemyIMPS0014.US.DG.COM at INTERNET-HUSKY
Date:    26/01/98 16:27

Good morning -

I'm trying to do the following:

I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
together 3 of the bits within the byte.

ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)

There doesn't seem to be any bit wise 'or' functions. Any ideas on how
to implement this?

Daniel Najemy -  Data General Corporation, Numaliine Power Systems

Steve Lawther wrote:
>
>      Daniel,
>
>      Best I can do of the top of my head is:-
>
>         RLF     TEMP, W
>         IORWF   TEMP, F
>         RLF     TEMP, W
>         IORWF   TEMP, F
>
>      OR'ed result in TEMP,5
>      Trashes TEMP and W
>      4 cycles
>
>      I'm sure somebody can do it better
>
>                 Steve Lawther

Good idea Steve, but how 'bout:

RLF    TEMP,W
ANDLW  ((1<<3) | (1<<4) | (1<<5))<<1
RLF    RESULT,F

Scott
Najemy, Daniel wrote:

> Good morning -
>
> I'm trying to do the following:
>
> I have a byte (let's call it TEMP), and I'm trying to logically 'OR'
> together 3 of the bits within the byte.
>
> ie. RESULT = (TEMP,3) or (TEMP,4) or (TEMP,5)
>
> There doesn't seem to be any bit wise 'or' functions. Any ideas on how
> to implement this?
>
>
> Daniel Najemy -  Data General Corporation, Numaliine Power Systems

if you are talking about doing or  with higher with lower nibbles this is
what you can do.

cblock        00
lower
result
endc

movf          temp,w        ; temp is your byte        example
00001111
swapf         temp,w          ;                         now temp
is    11110000
movwf        lower            ; save swaped nibbles
iorwf           temp,w            ; do or w with temp w is lower
and temp is higher
movwf          result            ; save it in result
movwf           portb            ; display the result on portb

it is not tested  if this is what you need I can make it work and send
it to you.

Andre  Abelian

==========================================
= http://www.compufire.com               =
= andrecompufire.com             =
= mcu-engineeringcompufire.com   =
= Andre Abelian: Engine Electronics, Inc.=
= Tel 909-589-5485  Fax 909-598-5695     =
==========================================

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...