'bittest on W'
Agnes en Henk Tobbe
I tried the following to see if the reslt of a substraction was negative...
movf test, w
btfss w, 7 ; see if the MSB in W is set
but it did not work......
what works is
after the substraction
btfss temp, 7
Can anyone tell how come? Cannot bits in W be tested?
Agnes en Henk Tobbe wrote:
> Can anyone tell how come? Cannot bits in W be tested?
Nope. W is not a register as all the others. W can be written too and
read from, but cannot be manipulated as with other registers.
W is the working register for the ALU and shouldn't be thought of as an
You have to do things like you did in your second example.
Harold M Hallikainen
|On Thu, 18 Nov 1999 06:56:49 +1100 Agnes en Henk Tobbe
<BIGPOND.COM> writes: tobbe
>I tried the following to see if the reslt of a substraction was
>movf test, w
>btfss w, 7 ; see if the MSB in W is set
>but it did not work......
>what works is
>after the substraction
>btfss temp, 7
>Can anyone tell how come? Cannot bits in W be tested?
On most PICs, the W register is not in the "file register" map,
so "F" instructions such as btfss do not work. The 17c and 18c
processors have wreg, which IS in the file register map, so you can use
these instructions there. Note that "w" is 0 and "f" is 1 in the
processor include files so you can use them as the destination bit in
instructions that take a destination bit.
Finally, with the SUB instructions on a PIC, you can check for a
negative result by checking the carry bit of the status register. The
bit is set if the result of the subtraction was positive and clear if the
result was negative.
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: dl.http://www.juno.com/dynoget/tagj.
Hi Agnes en Henk Tobbe.
> I tried the following to see if the reslt of a substraction was negative...
> movf test, w
> sublw 0x0x
> btfss w, 7 ; see if the MSB in W is set
> do this
> do that
It will not work. W register in 16Cxx is something special ;-)
You can't apply btfss/btfsc operations to it.
You need to put W value to some temp location first and finally
check temp with btfss/btfsc commands.
BTW. For what you've copied test in W register.
Apply btfsc/btfss directly to test register. ;-)
1. ANDLW 0x80 ; will test bit .7 in W, other bits are cleared ;-)
ANDLW 0x40 ; test bit .6
result of operation in _Z flag (=0 means bit=1 otherwise bit=0 result to
ANDLW is destructive command. You cannot restore W if you didn't save it
2. ADDLW 0x88 ; will test bits .7 and .3
results of operation in _C and _DC flags. To restore initial W just
ADDLW -0x88 ;-)
You can also apply XORLW value command
to check identity W to some value. It is useful command
(sometimes) 'cause you can do comparison for alot of values
and restore W after that to initial value.
XORLW B_CONST^A_CONST ;compare with B_CONST
XORLW C_CONST^B_CONST ;compare with C_CONST
XORLW LAST_CONST ;last used const value -> restore initial W
More... (looser matching)
- Last day of these posts
- In 1999
, 2000 only
- New search...