piclist 2003\03\02\123721a >
Thread: Some Basic Questions
face picon face BY : Olin Lathrop email (remove spam text)

> 1) incf, rlf, rrf type instructions do not seem to work properly on W.
> Is it so ? Why ?

These instructions only operate on "file registers", which does not
include W.  The result of these operations can be written back either to
the file register or to W, depending on the second operand (default is
write result back to the file register).  Unfortunately Microchip allows
the second operand to be either 0 or 1 to select W or the file register
instead of making this a special syntax.  They therefore define the
constants W and F in the include file to be 0 and 1 respectively.  This
means W and F are defined like any other symbols.  The instruction

   incf   w

is therefore perfectly legal syntax, although this increments the register
at location 0, not W.  Again, the W register is not mapped into the file
register address space.  Note that the instruction

   addlw  1

increments W by 1, although the effect on the flag bits is different.  The
INCF instruction only effects the Z flag, whereas the ADDLW instruction
also effects the C and DC flags.

> 2) I entered the following code assembled and ran MPSIM
>             clrw
>             incf  W,W
>             incf   W,W
>             incf   W,W
>     While single stepping through , W is incremented on the first incf
> and not on the subsequent two incf . WHY

Very good question.  W is cleared by the CLRW instruction.  The next
instruction increments data memory location 0 and writes the result into
W.  Location 0 is actually the INDF register, which is a special case.  It
is not a fixed register at all, but an alias for whatever location FSR and
the IRP bit of STATUS are pointing to.  This apparently was pointing to a
register that contained 0 (when FSR points to INDF it always reads 0).
The 0 value was incremented and written to W, thereby appearing to
increment W by 1.  The following instructions continue to do the same
thing.  Since INDF didn't get changed they still start with 0, increment
it to 1, and write it to W, thereby appearing to do nothing.

Note that the W is mapped into the RAM address space as "WREG" on the 18
family PICs.

Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

http://www.piclist.com hint: To leave the PICList
<000701c2e0e2$2f5deab0$0300a8c0@main> 7bit

See also: www.piclist.com/techref/microchip/languages.htm?key=basic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Some Basic Questions

month overview.

new search...