The Zero Flag

The Zero flag is a bit which indicates if the result of an operation results in a value of 0. The flag will change state on both accumulator and X register operations.
It will also change state on loading a value to the accumulator or X register.

  • BRZ - The Branch if Zero Flag Set Command

  • BNE - The Branch if Zero Flag Cleared Command

  • CMP - Will set Zero Flag if equal

  • CMPX - Will set Zero Flag if equal

  • INC - Will set Zero Flag if incremented from 255

  • INCX - Will set Zero Flag if incremented from 255

  • DEC - Will set Zero Flag if decremented from 1

  • DECX - Will set Zero Flag if decremented from 1

  • DIV - Will clear all flags

Examples

Example 1

{
LDA #3          //Load 3 into the Accumulator
CMP #3          //Compare if the Accumulator value is 3
BRZ EasyMatch   //Will branch to the label "EasyMatch:" because they are equal.

LDA ~2          //Load ~2 memory location
CMP #0x00       //Compare if it is 0x00
BRZ P1          //If it matches branch to label "P1:" If it doesn't match continue.
CMP #0x01       //Compare if it is 0x01
BRZ P2          //If it matches branch to label "P2:"  If it doesn't match continue.
CMP #0x02       //Compare if it is 0x02
BRZ P3          //If it matches branch to label "P3:"  If it doesn't match continue.
CMP #0x03       //Compare if it is 0x03
BRZ P4          //If it matches branch to label "P4:"  If it doesn't match continue.

LDA ~13         //Loads the value in ~13
BRZ End         //If the value is zero it branches to the label "End"
}

Example 2

Task1()
{
LDA #3        //Load 3 into the Accumulator
CMP #5        //Compare if the Accumulator value is 5
BNE NoMatch   //Will branch to the label "NoMatch:" because they are not equal.

LDA ~7      //Load ~7
CMP #0x03   //Compare it to 0x03
BNE Label   //If it matches continue on if it didn't match branch to "Label:"

Start(0x1c,112,x,x,x,x,x)//Watches all incomming 1C messages for area 112.
    copy @0,~0,7 //Copy the msg to ~0-6.  ~1 is area, ~3 is preset, ~5 is offset.
    LDA ~3       //Get Preset byte (The Op code)
    CMP #0x03    //Check if the incomming Preset Byte matches opcode for P4
    BNE ON       //If preset 4 branch to the label "ON:" if P4 continue.

LDA ~7      //Load ~7
BNE Label   //If the value is anything but zero branch to "Label:"
}