Negative Flag

From NES Hacker Wiki
Jump to: navigation, search

The Negative Flag (N) is bit 7 in the Processor Status Register. After any arithmetical, storage, or logical operation instruction is performed on registers A, X, or Y, the N flag is set equal to the 7th bit of the result. Thus, it's a 1 if the result is negative, a 0 if the result is positive. This flag assumes a signed byte and should be ignored on unsigned bytes. Decimal mode affects this flag differently, but since the NES doesn't have decimal mode, it is irrelevant to cover it.

Examples

The following example loads A with a negative number and positive number to show how the flag is set.

0001:A9 80    LDA #$80           ; Loads A with $80, which is -127 as a signed byte.
                                 ; In binary, this is 10000000. Since the N flag takes the value of the 
                                 ; 7th bit, it is set to 1 after this instruction is executed.

0002:A9 01    LDA #$7F           ; Loads A with $7F, which is 127 as a signed byte.
                                 ; In binary, this is 01111111. Since the N flag takes the value of the
                                 ; 7th bit, it is set to 0 after this instruction is executed.


Opcodes

The following opcodes affect the negative flag.