Searching \ for '[PIC:] code challenge - test both nibbles non-zero' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'code challenge - test both nibbles non-zero'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] code challenge - test both nibbles non-zero'
2001\01\23@161504 by jamesnewton

picon face
Ok, I'm storing two 4 bit wide variables in one byte (file register) and I
need to test that neither variable is zero. i.e. the byte is not 0X or X0
hex were X is any 4 bit value. The best I can do is 7, any better?

       P = pic16c55
       #include <16c55.inc>   ; processor assembler definitions
       _CONFIG _xt_osc & _wdt_off & _protect_off
reset start

org 8
BufTyp  Res     d'1' ; Pin number to set (0-7).

org 0
start
       CALL noznibs
;       ....
       HALT

noznibs
       MOVF BufTyp,w
       ANDLW 0x0F
       BTFSC status,z
        RET
       SUBWF Buftyp,w
       BTFSC status,z
        RET

---
James Newton (PICList Admin #3)
spam_OUTjamesnewtonTakeThisOuTspampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\23@170228 by James Paul

flavicon
face
James,

Why not check the register for zero.  If it is zero, both nibbles
are zero.  If non zero, check for greater than 15.  If it is,
subtract 15, and what remains is the upper nibble.  Is this correct?

                                          Regards,

                                            Jim

On Tue, 23 January 2001, j newton wrote:

{Quote hidden}

jimspamKILLspamjpes.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\23@172655 by jamesnewton

face picon face
Doh!

Thanks.

---
James Newton (PICList Admin #3)
.....jamesnewtonKILLspamspam.....piclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2001\01\23@174227 by Andrew Warren

flavicon
face
j newton <EraseMEjamesnewtonspam_OUTspamTakeThisOuTgeocities.com> wrote:

> Ok, I'm storing two 4 bit wide variables in one byte (file register)
> and I need to test that neither variable is zero. i.e. the byte is not
> 0X or X0 hex were X is any 4 bit value. The best I can do is 7, any
> better?
>
>         P = pic16c55
> ....
>         MOVF BufTyp,w
>         ANDLW 0x0F
>         BTFSC status,z
>          RET
>         SUBWF Buftyp,w
>         BTFSC status,z
>          RET

James:

Does it HAVE to work on a 16C55?  If you had an ADDLW instruction,
you could do this:

   MOVF    BufTyp,W
   ADDLW   0xEF
   SKPNC
   SKPDC
   RETLW   0

-Andy


=== Andrew Warren --- aiwspamspam_OUTcypress.com
=== Staff Systems Engineer, IPD
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\23@181337 by Andrew Warren

flavicon
face
James Newton <@spam@jamesnewtonKILLspamspampiclist.com> wrote:

Richard Ottosen <KILLspamrottosenKILLspamspamidcomm.com> wrote:

> Is this what you want?
>
>  noznibs
>          SWAPF BufTyp,W
>          ANDWF BufType,W
>          BTFSC status,Z
>           RET
>
> See, hardware guys can write code.  :-)

Yeah, I suppose that's true... But the real question is whether they
can write code that WORKS.

The code should return if either the low or the high nibble of BufTyp
is equal to 0, right?  In other words, we should return if BufTyp =
0xA0, and we should NOT return if BufTyp = 0xA5.  Let's try 0xA0
first:

   BufTyp = 1010 0000:

       SWAPF BufTyp,W    ;BufTyp = 1010 0000, W = 0000 1010
       ANDWF BufTyp,W    ;BufTyp = 1010 0000, W = 0000 0000
       BTFSC status,Z    ;this branch is NOT taken,
       RET               so we return.

That one works fine, so let's try 0xA5...

   BufTyp = 1010 0101:

       SWAPF BufTyp,W    ;BufTyp = 1010 0101, W = 0101 1010
       ANDWF BufTyp,W    ;BufTyp = 1010 0101, W = 0000 0000
       BTFSC status,Z    ;this branch is NOT taken,
       RET               ;and we return.

Oops.

-Andy


=== Andrew Warren --- RemoveMEaiwTakeThisOuTspamcypress.com
=== Staff Systems Engineer, IPD
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\23@191842 by rottosen

flavicon
face
Andrew Warren wrote:
{Quote hidden}

Ouch!
No problem. We can fix it in software.  ;-)


-- Rich

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\24@082422 by Drew Vassallo

picon face
> > See, hardware guys can write code.  :-)
>
>Yeah, I suppose that's true... But the real question is whether they
>can write code that WORKS.

Although I didn't offer any code solutions myself, I just had to laugh at
this bit of humor :)  Too funny.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@110807 by jamesnewton

face picon face
It does have to work on a 16c55 (actually an SX 28) but can't I just:

       MOVLW 0xEF
       ADDF    BufTyp, W
       SKPNC
       SKPDC
       RETLW 0

???

Seems like that would work and its darn tricky... Nice idea! Thanks.

---
James Newton (PICList Admin #3)
RemoveMEjamesnewtonspamTakeThisOuTpiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2001\01\24@135244 by Andrew Warren

flavicon
face
James Newton <jamesnewtonEraseMEspam.....piclist.com> wrote:

> > Does it HAVE to work on a 16C55?  If you had an ADDLW
> > instruction, you could do this:
> >
> >     MOVF    BufTyp,W
> >     ADDLW   0xEF
> >     SKPNC
> >     SKPDC
> >     RETLW   0
>
> It does have to work on a 16c55 (actually an SX 28) but can't I just:
>
>         MOVLW 0xEF
>         ADDF    BufTyp, W
>         SKPNC
>         SKPDC
>         RETLW 0

   Sigh... Can you tell that it's been a while since I've written
   any PIC code?

   Of course your re-ordering will work, James; I should have
   written it that way originally.

   -Andy


=== Andrew Warren --- EraseMEaiwspamcypress.com
=== Staff Systems Engineer, IPD
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


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