BRZ - Branch if Zero Command
Branches if the zero flag is set. This occurs if you load a value of 0 into the accumulator or a comparison is equal.
If the result of the CMP comparison is zero(equal) then both the accumulator and the compared values must be the same (accumulator = 5 and argument = 5. 5-5=0).
When this is the case the task will branch (skip) to the label referenced in the BRZ command.
If the comparison is not zero then the task keeps rolling past.
BNE (Branch Not Equal) is the opposite of this.
You never need to compare to "0x00"! If the value is zero the zero flag will be set and BRZ will branch. Simply load your memory and use BRZ to check if the value is 0. |
Examples
{
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"
}