piclist 2003\03\02\121608a >
Thread: Some Basic Questions
face BY : Ian McLean email (remove spam text)

You need to re-evaluate your programming techniques a little for PIC
assembly.  W is not a file register, but the working register.  incf =
increment FILE register, etc.

The reason the behaviour you are witnessing with incf W, W is because it
incremented a FILE register pointed to by W, and placed the result in W.
The register pointed to by W was 0x00, because you cleared W.  File register
at 0x00 was zero to start with (no guarantees on that though !).  That is
why each incf W,W came back with the same result !

Get used to not performing these operations on W.  W is really just a go
between for file registers, and for setting flags in STATUS, such as Zero,
Carry, etc. (note that many file register operations set STATUS flags
anyway, so even this usage is really unnecessary except for code
optimization sometimes) - all the juicy things happen with file registers.
It's a bit of a PIC thing, just get used to moving W into, say, a temporary
register before performing bit shifting, increments, or decrements.  Really,
you should only be doing this on file registers to start with (i.e.
re-evaluation of technique here ;) ).  W is effected differently for many of
these operations.  Any static results you wish to keep should be in file
registers to start with.  The reasons for this are many, for example,
optimisation, and to keep each instruction to a single cycle.

1) Because the assembler allows W to point to a file register for these
operations.  I don't personally like this sort of syntax though, and think
it SHOULD report these as errors.

To recode 2) properly, you would write something like:

movwf   Temp
incf    Temp, F
incf    Temp, F
incf    Temp, W ; (last incf places result in W)

But really, you should be using a file register in the first place, not W -
and the result becomes even simpler, e.g.

clrf    Temp
incf    Temp, F
incf    Temp, F
incf    Temp, F

or optimized ...

movlw   0x03
addwf   Temp

Hope all this helps

{Original Message removed}
<000701c2e0df$2a34d6f0$0c00a8c0@deepthought> 7bit

In reply to: <OE44NmgHvnRQgukfMHT00002d73@hotmail.com>
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...