Conditional Statements
. branch if value of R meets one of six conditions negative, zero, positive, non-negative, non-zero, non-positive
if X < Y goto Z |
Mov X, R0
|
|
Sub Y, R0 |
|
Jmp negative Z
|
. Condition codes: indicate whether last quantity computed or loaded into a location is negative, zero, or positive
Machines implement conditional jumps in one of two ways.
One way is to branch if the value of a designated register meets one of the six conditions: negative, zero, positive, non-negative, non-zero, and non-positive. On such a machine a three-address statement such as if x < y goto z can be implemented by subtracting y from x in register R, and then jumping to z if the value in register is negative.
A second approach, common to many machines, uses a set of condition codes to indicate whether the last quantity computed or loaded into a register is negative, zero or positive.
|