Information Technology Reference
In-Depth Information
TABLE 2.6 Examples of Condition Flags
Flag name
Meaning
Negative (N)
Set to 1 if the result of the most recent operation
is negative, it is 0 otherwise
Zero (Z)
Set to 1 if the result of the most recent operation
is 0, it is 0 otherwise
Overflow (V)
Set to 1 if the result of the most recent operation
causes an overflow, it is 0 otherwise
Carry (C)
Set to 1 if the most recent operation results in a
carry, it is 0 otherwise
the change made in the PC by the branching instruction can be conditional based on
the value of a specific flag. Examples of these flags include the Negative (N), Zero
(Z), Overflow (V), and Carry (C). These flags represent the individual bits of a
specific register, called the CONDITION CODE (CC) REGISTER. The values of
flags are set based on the results of executing different instructions. The meaning
of each of these flags is shown in Table 2.6.
Consider, for example, the following group of instructions.
LOAD
#
100, R 1
Loop:
ADD
(R 2 )
รพ
, R 0
DECREMENT R 1
BRANCH-IF-GREATER-THAN Loop
The fourth instruction is a conditional branch instruction, which indicates that if
the result of decrementing the contents of register R 1 is greater than zero, that is,
if the Z flag is not set, then the next instruction to be executed is that labeled by
Loop. It should be noted that conditional branch instructions could be used to exe-
cute program loops (as shown above).
The CALL instructions are used to cause execution of the program to transfer to a
subroutine. A CALL instruction has the same effect as that of the JUMP in terms of
loading the PC with a new value from which the next instruction is to be executed.
However, with the CALL instruction the incremented value of the PC (to point to the
next instruction in sequence) is pushed onto the stack. Execution of a RETURN
instruction in the subroutine will load the PC with the popped value from the
stack. This has the effect of resuming program execution from the point where
branching to the subroutine has occurred.
Figure 2.12 shows a program segment that uses the CALL instruction. This pro-
gram segment sums up a number of values, N, and stores the result into memory
location SUM. The values to be added are stored in N consecutive memory locations
starting at NUM. The subroutine, called ADDITION, is used to perform the actual
addition of values while the main program stores the results in SUM.
Table 2.7 presents some common transfer of control operations.
Search WWH ::




Custom Search