The Minus Flag

The Minus flag is a bit which indicates if the result of an operation results in a negative result or the MSB being set. The flag will change state on both accumulator and X register operations.

  • BMI - The Branch if Minus Flag Set Command

  • BCC - The Branch if Minus Flag Cleared Command

  • CMP - Will set Minus Flag if accumulator is greater

  • CMPX - Will set Minus Flag if X register is greater

  • DEC - Will set Minus Flag if decremented from 0

  • DECX - Will set Minus Flag if decremented from 0

  • DIV - Will clear all flags

Examples

Example 1

{
LDA #130        //Put the fixed decimal value 130 into the Accumulator
BMI Label       //Branch to Label as Minus flag is set

LDA #120        //Put the fixed decimal value 120 into the Accumulator
BMI NotEnough   //Won't branch as Minus flag is not set
ADD #10         //Add 10 more. 120+10=130
BMI Label       //Branch to Label as Minus flag is set

LDA #0x06       //Put the fixed hex value 0x06 into the Accumulator
CMP #0x08       //0x06-0x08= -2 Set the Minus flag
BMI Label       //Will branch as Minus flag is set
}

Example 2

Task1()
{
LDA #120    //Put the fixed decimal value 120 into the Accumulator
BPL Label   //Branch to label as minus flag is not set

LDA #130    //Put the fixed decimal value 130 into the Accumulator
BPL TooHigh //Won't branch to label as minus flag is set
SUB #10     //Subtract 10. 130-10=120.
BPL Label   //Branch to label as minus flag is not set

DIV         //DIV command clears all flags

LDA #0x08       //Put the fixed hex value 0x08 into the Accumulator
CMP #0x06       //0x08-0x06= 2 Clear the minus flag
BMI Label       //Will branch as minus flag is not set
}