Truncated match.
PICList
Thread
'bittest on W'
1999\11\17@145953
by
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
but it did not work......
what works is
after the substraction
movwf temp
btfss temp, 7
di this
do that
Can anyone tell how come? Cannot bits in W be tested?
Henk Tobbe
VK2GWK
1999\11\17@155912
by
Quentin
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
actual register.
You have to do things like you did in your second example.
Quentin
1999\11\17@175321
by
Harold M Hallikainen
|
On Thu, 18 Nov 1999 06:56:49 +1100 Agnes en Henk Tobbe
<spam_OUTtobbeTakeThisOuT
BIGPOND.COM> writes:
>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
>
>but it did not work......
>what works is
>after the substraction
>
>movwf temp
>btfss temp, 7
>di this
>do that
>
>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.
Harold
Harold Hallikainen
.....haroldKILLspam
@spam@hallikainen.com
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.
1999\11\17@184708
by
Tony Nixon
1999\11\17@191153
by
Dmitry Kiryashov
|
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. ;-)
WBR Dmitry.
HINTS:
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
_Z=1)
ANDLW is destructive command. You cannot restore W if you didn't save it
before.
2. ADDLW 0x88 ; will test bits .7 and .3
results of operation in _C and _DC flags. To restore initial W just
ADDLW -0x88 ;-)
3.
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 A_CONST
SKPNZ
GOTO A_CONST_MATCH
XORLW B_CONST^A_CONST ;compare with B_CONST
SKPNZ
GOTO B_CONST_MATCH
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
- Today
- New search...