Searching \ for '[PIC]: Simplest Solutions always the hardest to fi' 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: 'Simplest Solutions always the hardest to fi'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Simplest Solutions always the hardest to fi'
2001\10\24@113933 by Dylan Hillier

flavicon
face
Hello People,

Just curious about the PIC equivalent to an C if statement to compare one
byte to another:

I have looked through the manual only to find that there seems to be only
instructions for bit oriented or counter skipping of next instruction.
I looked in the online help to come up with something like below, but it
appears only to be a macro used during compile time and skipped
when run through the debugger.

       IF W != 0
               CALL    SOME_ROUTINE
               GOTO STR_LOOP
       ENDIF


Is there a simple way of checking if byte 'A' = byte 'B' then call this
routine, else call this one.

Incase your wondering what im trying to do. Im trying to store strings in
the EEPROM that are zero terminated and read through them until i
reach  that zero.
eg.
EE_LINE1        DE      "My LiL EEPROM String ;o)", 0


While im on the topic of using internal EEPROM of a PIC16F84A, im yet again
confused as to some of the wording in the manual.
It says in section 5.0 that this device has 64 bytes(chars) of data with
address range from 0h through to 3fH.  BUT this appears to be
in conflict with the memory model shown in figure 2-1 in section 2.  My
main concern is when defining the use of EEPROM in the source
where on earth to i ORG it to ?  The online help mentions something
about  H'2100', but where did this value come from.

arggggg.. driving me insane. I will be bald from pulling my hair out soon.


Regards,

   Dylan Hillier.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@120025 by Jeff DeMaagd

flavicon
face
----- Original Message -----
From: Dylan Hillier <spam_OUTxoniusTakeThisOuTspamIHUG.COM.AU>

> Just curious about the PIC equivalent to an C if statement to compare one
> byte to another:
>
>         IF W != 0
>                 CALL    SOME_ROUTINE
>                 GOTO STR_LOOP
>         ENDIF

> Is there a simple way of checking if byte 'A' = byte 'B' then call this
> routine, else call this one.

Sorry, nothing as simple as a C instruction but it's not too complex on a
byte level.

If comparing to zero, check the zero flag after you put the value into W.
Using these instrucions needs understanding of the assembler instructions.
Here is a generalized example:

; assuming we start out with a value in W
   skpnz
   goto end    ;if w=0, leave
   call    some_routine
   goto  str_loop
end

If you need see if two registers are equal or not equal, try this.

   movfw    reg_a
   subwf    reg_b,w
   skpnz
   goto end                    ;if they are equal, end
   call    some_routine    ;if they are equal perform operation
   goto  str_loop
end

You can invert the logic by replacing skpnz with skpz.  The skpnz
instruction can be replaced with skpc or skpnc if you want to compare sizes,
do one operation of a>b, another if a<=b and so on.

Jeff

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@120811 by Don Hyde

flavicon
face
The PIC instruction set is uncommonly filled with things that on other
processors are done with a particular instruction, but which are done on the
PIC by some clever use of one of its small number of instructions.

The bit-oriented instructions can test conditions in the status register,
including such things as the Z or zero bit and the C or carry bit.  The
MPASM recognizes special mnemonics (they are actually in the help file!) for
several of these, including skpz and skpnz, which skip if zero flag is set
or not set respectively.

The MOV family of instructions set the Z bit as a side effect, so your
example can be coded as:

       MOVF    WWW,f           ; Assuming WWW is a variable in memory, and
not the W register...
                               ; At first glance, this instruction looks
like a complicated NOP,
                               ; since it moves WWW back onto itself, but
as a side effect, it
                               ; tests the value for zero and sets the Z
flag
       skpz
       call    SOME_ROUTINE

If you meant for your W to mean the W register, then you can probably skip
the first instruction, because almost any instruction that leaves a value in
W alters the Z flag to reflect the contents of W.  One notable exception is
RETLW.

With the PIC, "You can't tell the players without a scorecard!", so keep the
instruction set pages of the datasheet handy to check for all the side
effects, especially which instructions alter which flags.

> {Original Message removed}

2001\10\24@134240 by andy n1yew

picon face
hows about:
                   CALL TESTZERO

TESTZERO MOVF       TESTME,W
                   SUBLW     0
                   BTFSC      STATUS,Z
                   GOTO       ZEROROUTINE
                   GOTO       NOTZEROROUTINE

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@143936 by Bob Barr

picon face
andy n1yew wrote:
>
>hows about:
>                     CALL TESTZERO
>
>TESTZERO MOVF       TESTME,W
>                     SUBLW     0
>                     BTFSC      STATUS,Z
>                     GOTO       ZEROROUTINE
>                     GOTO       NOTZEROROUTINE
>

Two minor nits to pick:

The 'SUBLW 0' isn't really necessary. The data sheet shows that the 'movf'
instruction sets/clears the Z flag directly.

There's no need to use a 'GOTO' to get to the NOTZEROROUTINE label. The code
for handling the non-zero case could just start right there. If Z is set,
goto the zero routine, else just fall through to the non-zero routine.

Regards, Bob


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@144358 by uter van ooijen & floortje hanneman

picon face
> Just curious about the PIC equivalent to an C if statement to compare one
> byte to another:

Why not get yourself a (free) C compiler and see what it makes of your
statement?

Wouter van Ooijen

Van Ooijen Technische Informatica: http://www.voti.nl
Jal compiler for PIC uC's:  http://www.xs4all.nl/~wf/wouter/pic/jal

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@150022 by Byron A Jeff

face picon face
On Wed, Oct 24, 2001 at 01:35:14PM -0400, andy n1yew wrote:
> hows about:
>                     CALL TESTZERO
>
> TESTZERO MOVF       TESTME,W
>                     SUBLW     0
>                     BTFSC      STATUS,Z
>                     GOTO       ZEROROUTINE
>                     GOTO       NOTZEROROUTINE
>

The sublw is unnecessary. MOVF affects the zero flag upon load. So if TESTME
is 0, then the zero flag will be set when moved.

An even better snippet that doesn't use W at all:

testzero        movf    testme,F
               btfsc   STATUS,Z
               goto    zeroroutine
               goto    notzeroroutine

BAJ

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@150710 by Olin Lathrop

face picon face
> Is there a simple way of checking if byte 'A' = byte 'B' then call this
> routine, else call this one.

    movf   bytea, w   ;get byte A
    xorwf  byteb, w   ;set Z flag if byte B = byte A
    btfss  status, z  ;both bytes are equal ?
    goto   noteq      ;no
;
;   Byte A equals byte B.
;
    blah, blah
    goto   outtahere
;
;   byte A differs from byte B.
;
noteq
    blah, blah

outtahere              ;all done with comparison

Of course the direct register banks must be set for access to BYTEA and
BYTEB.

> Incase your wondering what im trying to do. Im trying to store strings in
> the EEPROM that are zero terminated and read through them until i
> reach  that zero.
> eg.
> EE_LINE1        DE      "My LiL EEPROM String ;o)", 0

Then you don't need to compare two bytes, you only need to test whether one
byte is zero:

    movf   bytea      ;set Z if BYTEA is zero
    btfss  status, z  ;the byte is zero ?
    goto   notzero    ;no
    .
    .


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@155356 by Heinz Czychun

flavicon
face
At 1:46 AM +1000 10/25/01, Dylan Hillier wrote:
>Hello People,
>
>...<snip>....
>
>While im on the topic of using internal EEPROM of a PIC16F84A, im yet again
>confused as to some of the wording in the manual.
>It says in section 5.0 that this device has 64 bytes(chars) of data with
>address range from 0h through to 3fH.  BUT this appears to be
>in conflict with the memory model shown in figure 2-1 in section 2.

       I think your confusing program EEPROM with data EEPROM.

       Figure 2-1 in section 2 shows the program EEPROM accessed
through the program counter.


>  My
>main concern is when defining the use of EEPROM in the source
>where on earth to i ORG it to ?  The online help mentions something
>about  H'2100', but where did this value come from.

       I was surprised how difficult it was to find this info. In
30277b.pdf, the ICSP Guide (DS30262A), page 3-72 (111 of 138)
indicates that the data EEPROM starts at 0x2100.

>
>arggggg.. driving me insane. I will be bald from pulling my hair out soon.
>
>
>Regards,
>
>    Dylan Hillier.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\24@184827 by Tony Nixon

flavicon
picon face
Dylan Hillier wrote:
{Quote hidden}

Try..

http://www.bubblesoftonline.com/demo/helper.zip

From text like...

if Harry > Large goto DietTime

It puts this code into the clipboard so you can paste it into your own
code.

;
; if Harry > Large goto DietTime
;
       movf Harry,W
       subwf Large,W
       btfss STATUS,C
       goto DietTime
;


--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
salesspamKILLspambubblesoftonline.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\26@105220 by Peter L. Peres

picon face
Nice thread title ;-).

About the if: there are several ways. One is:

 movf  A,w
 subwf B,w             ; A-B == 0 if A==B -> Z=1
 btfsc STATUS,Z        ; btfsc for A!=B and btfss for A==B
 goto  dont

 call  some_routine
 goto  str_loop

dont: ; more code here

There a reequivalent ways to deal with other comparisons like A>B, B>=B
etc etc.

Wrt strings, ASCIIZ strings are sometimes easier stored as non-ASCIIZ
strings, with the high bit of the last character set. That would be:

; your: EE_LINE1        DE      "My LiL EEPROM String ;o)", 0
EE_LINE1        DE      "My LiL EEPROM String ;o", ')'+H'80

And then you actually print each char and test at the bottom of the loop,
which is convenient:

loop:
 ; do something to fetch char, put into temp_char or INDF or someplace
 call  display         ; the char in temp_char
 btfss temp_char,7     ; is the high bit set ?
 goto  loop            ; no, more

 ; yes it was: end

About storing data into EEPROM using the hex file, just ORG at 0x2100 and
then use DB as you need. I have never tried DE with this. As in:

 org 0x2100

ee_abc  db  'a','b','c'

To use ee_abc as an eeprom address symbol you need to substract 0x2100
from it. E.g.:

 movlw ee_abc-0x2100   ; the address of abc
 movwf EEADDR

Peter

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


2001\10\26@150643 by Olin Lathrop

face picon face
>   movf  A,w
>   subwf B,w             ; A-B == 0 if A==B -> Z=1
>   btfsc STATUS,Z        ; btfsc for A!=B and btfss for A==B

This is where is use my SKIP_WGT (skip if W was greater than) or SKIP_WLE
(skip if W was less than or equal to) macros.  These are cases where getting
the right sense of Z seems to be particularly confusing.  These macros and
other related ones are in STD.INS.ASPIC at http://www.embedinc.com/pic.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam.....embedinc.com, http://www.embedinc.com

--
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...