Searching \ for '[PIC]: XORWF and the carry bit' 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: 'XORWF and the carry bit'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: XORWF and the carry bit'
2002\05\02@005200 by Kevin Olalde

flavicon
face
From code generated from
http://www.piclist.com/techref/piclist/codegen/constdivmul.htm I've got a piece
of code that uses the following sequence:

       movlw   0x01
       xorwf   STATUS, f       ;complement carry

This works fine under the MPLAB simulator for a PIC16F871.  However when I run
that routine on chip, the carry isn't flipped.  I observed this non-flippin'
behavior using the Microchip ICD.

As always with all things PIC, I'm assuming I'm missing something.  The
datasheet for the 871, however,  says the XORWF instruction doesn't touch the C
flag, so I don't see why the bit isn't set (or cleared as the case may be, in my
case I was expecting to see it get set).

I've coded around this by using bit test and bit set/clear instructions, so I
can get on with the project, but if anyone has any insight on this I'd
appreciate it.

Thanks,
Kevin

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


2002\05\02@011913 by Bob Ammerman

picon face
From section 2.1.1.1 of the datasheet DS30292C:

<QUOTE>
The STATUS register can be the destination for any
instruction, as with any other register. If the STATUS
register is the destination for an instruction that affects
the Z, DC or C bits, then the write to these three bits is
disabled. These bits are set or cleared according to the
device logic. SWAPF and MOVWF instructions are used to alter the
STATUS register, because these instructions do not
affect the Z, C or DC bits from the STATUS register. For
other instructions not affecting any status bits, see the
"Instruction Set Summary."
<ENDQUOTE>

This sounds like any instruction that sets or clears ANY of the Z, C and DC
to report status will inhibit writes to ALL of the Z, C and DC instructions.

In fact, a little bit later in the same section:

<QUOTE>
The STATUS register contains the arithmetic status of
the ALU, the RESET status and the bank select bits for
For example, CLRF STATUS will clear the upper three
bits and set the Z bit. This leaves the STATUS register
as 000u u1uu (where u = unchanged).
<ENDQUOTE>

Note that he CLRF instruction is defined to set the Z bit, but not co change
C or DC. However, note that C and DC are unchanged by a CLRF. This seems to
support the idea that an instruction that tweaks any of the statuts bits
prevents normal writes all all of them.

This code should work:

       movf      status,w
       xorlw     1
       movwf    status

Bob Ammerman
RAm Systems

From: "Kevin Olalde" <spam_OUTkevinTakeThisOuTspamOLALDE.ORG>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Thursday, May 02, 2002 12:10 AM
Subject: [PIC]: XORWF and the carry bit


> From code generated from
> http://www.piclist.com/techref/piclist/codegen/constdivmul.htm I've got a
piece
> of code that uses the following sequence:
>
>         movlw   0x01
>         xorwf   STATUS, f       ;complement carry
>
> This works fine under the MPLAB simulator for a PIC16F871.  However when I
run
> that routine on chip, the carry isn't flipped.  I observed this
non-flippin'
> behavior using the Microchip ICD.
>
> As always with all things PIC, I'm assuming I'm missing something.  The
> datasheet for the 871, however,  says the XORWF instruction doesn't touch
the C
> flag, so I don't see why the bit isn't set (or cleared as the case may be,
in my
> case I was expecting to see it get set).
>
> I've coded around this by using bit test and bit set/clear instructions,
so I
{Quote hidden}

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


2002\05\02@012754 by Tony Nixon

flavicon
picon face
Kevin Olalde wrote:
>
> From code generated from
> http://www.piclist.com/techref/piclist/codegen/constdivmul.htm I've got a piece
> of code that uses the following sequence:
>
>         movlw   0x01
>         xorwf   STATUS, f       ;complement carry
>


It most likely works the same as this.

       clrf STATUS

You expect STATUS to be clear, but the Z flag will be set after the
instruction executes.

I "think" that any instruction that causes a change in the STATUS Z C or
DC bits with the STATUS as the destination, automatically masks these
bits from the instruction.

XORWF affects the Z bit and therefore locks out the others.

Try BSF or BCF because these do not affect any STATUS bits.

Of course I could be wrong :-)

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


2002\05\02@014624 by Kevin Olalde

flavicon
face
Bob Ammerman wrote:
>
> >From section 2.1.1.1 of the datasheet DS30292C:
>
> <QUOTE>
> The STATUS register can be the destination for any
> instruction, as with any other register. If the STATUS
> register is the destination for an instruction that affects
> the Z, DC or C bits, then the write to these three bits is
> disabled. These bits are set or cleared according to the
> device logic. SWAPF and MOVWF instructions are used to alter the
> STATUS register, because these instructions do not
> affect the Z, C or DC bits from the STATUS register. For
> other instructions not affecting any status bits, see the
> "Instruction Set Summary."
> <ENDQUOTE>

Not sure why, but I read that to mean that it skips changing the bits that the
instruction affects (instead of all the bits), just assumed.

OK, I understand now.  Not what I expected, but seems to be true from testing
(and the quoted text).

So I guess two things left, is this a bug in MPLAB (is it well known to not do
well in this area)?
The code generator should be updated (I didn't see the source).  Does Nikolai
still 'support' them?

Thanks!
Kevin

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


2002\05\02@140616 by jamesnewton

face picon face
source= http://www.piclist.com/postbot.asp?id=piclist\2002\05\02\005200a

Hows this for service:

Nik posted an update to the server earlier today that fixes the problem. Try
it now (be sure to hit refresh) and I think you will find the code now
avoids this issue. For example, try:

www.piclist.com/cgi-bin/constdivmul.exe?Acc=ACC&Bits=16&endian=little
&Const=0.889&ConstErr=0.5&Temp=TEMP&cpu=pic16

---
James Newton: PICList.com webmaster, former Admin #3
.....jamesnewtonKILLspamspam.....piclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com

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


2002\05\02@224502 by Kevin Olalde

flavicon
face
Very cool.  Thanks Nik!

Kevin

"James Newton. Admin 3" wrote:
{Quote hidden}

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


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