On page 24 of version 3.2.18d of the PLC User Guide we have the following sample code:
TSTEQ IP1 1 # sets zero bit based on the result of the test instruction
BNZ label # branches to label if zero bit is non-zero
…and the following description of the TSTEQ opcode:
Tests if a is equal to b. Boolean result loaded into optional
destination (d). Zero bit updated with result. If test
evaluates to false then the next instruction is skipped.
My question/confusion starts with that last sentence, “If test evaluates to false then the next instruction is skipped.” If this statement is accurate, then it seems to me that any BNZ or BZ command that immediately follows a TSTEQ command will either always branch (might as well be a GOTO) or never branch (might as well be a NOP).
Take the sample code above, for example. If IP1 doesn’t equal 1 (test evaluates to false), then the BNZ command (“the next instruction”) is skipped. Conversely, if IP1 does equal 1 (test evaluates to true), then the zero bit is set and the branch should always occur and therefore could have been a GOTO command.
Clearly I’m missing something or don’t understanding how the zero bit is set as a result of a TST command. Any clarification here would be appreciated.
Thanks,
-Randy
TSTEQ IP1 1 # sets zero bit based on the result of the test instruction
BNZ label # branches to label if zero bit is non-zero
…and the following description of the TSTEQ opcode:
Tests if a is equal to b. Boolean result loaded into optional
destination (d). Zero bit updated with result. If test
evaluates to false then the next instruction is skipped.
My question/confusion starts with that last sentence, “If test evaluates to false then the next instruction is skipped.” If this statement is accurate, then it seems to me that any BNZ or BZ command that immediately follows a TSTEQ command will either always branch (might as well be a GOTO) or never branch (might as well be a NOP).
Take the sample code above, for example. If IP1 doesn’t equal 1 (test evaluates to false), then the BNZ command (“the next instruction”) is skipped. Conversely, if IP1 does equal 1 (test evaluates to true), then the zero bit is set and the branch should always occur and therefore could have been a GOTO command.
Clearly I’m missing something or don’t understanding how the zero bit is set as a result of a TST command. Any clarification here would be appreciated.
Thanks,
-Randy