Question

If the W register contains 0 and I try to subtract some value from it, what would the value in the register become? Would it set the zero flag inside STATUS register and how can I use it to check if we are going to go to negative numbers?

For example, in this code

MOVLW b'00000000' ; W has value 0
SUBLW b'00000001' ; trying to decrement

I'm trying to decrement W register, what are the consequences of it?

Était-ce utile?

La solution

SUBLW will subtract the literal from the value in W regardless of W being zero or not. The result of course will be like

W = W - literal;

If W = 0 then it's a negation if the type is signed, or a wrap around if it's unsigned.

Before: W = 00000000
          -        1
────────────────────
After:  W = 11111111 (-1)

But if W is zero, subtract a non-zero number from it will make it non zero, thus the zero flag will not be ON

If you need to check whether the value is negative or not, use both carry flag and zero flag

Result    Carry  Zero
Positive  1      0
Zero      1      1
Negative  0      0

http://www.pcbheaven.com/picpages/Mathematic_Instructions/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top