You seem to have the idea that ZF generally means that the operands were equal. This is wrong. It is not a property of the ZF that it shows whether the operands were equal. Instead, it is a property of
CMP that it sets the zero flag if the operands are equal. This code snippet does not execute
Instead, this code snippet executes
TEST, which works differently. It says ZF exactly in those cases where no bit is set in both the first and the second operand. So if AL is nonzero,
TEST AL,AL will find that some bits (all that are set in AL) are set in both the first and the second operand, and clear ZF. On the other hand, if AL is zero, no bit in AL is set, so there is no bit that is set in either the first or second operand, and ZF will be set.
The test for zero can be performed with the same effect using either
OR, where both operands are the same register. You will find all three variants in real-world code to test whether a register is zero.