문제

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?

도움이 되었습니까?

해결책

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top