Hardware Reference
In-Depth Information
zero to a memory word or register is extremely common when initializing a calcu-
lation. Moving zero is, of course, a special case of the general move data instruc-
tions. For efficiency, a CLR operation, with only one address, the location to be
cleared (i.e., set to zero), is often provided.
Adding 1 to a word is also commonly used for counting. A monadic form of
the ADD instruction is the INC operation, which adds 1. The NEG operation is an-
other example. Negating X is really computing 0
X , a dyadic subtraction, but
again, because of its frequent use, a separate NEG instruction is sometimes pro-
vided. It is important to note here the difference between the arithmetic operation
NEG and the logical operation NOT . The NEG operation produces the additive
inverse of a number (the number which when added to the original gives 0). The
NOT operation simply inverts all the individual bits in the word. The operations are
very similar, and in fact, for a system using ones' complement representation, they
are identical. (In twos' complement arithmetic, the NEG instruction is carried out
by first inverting all the individual bits, then adding 1.)
Dyadic and monadic instructions are often grouped together by their use, rath-
er than by the number of operands they require. One group includes the arithmetic
operations, including negation. The other group includes logical operations and
shifting, since these two categories are most often used together to accomplish data
extraction.
5.5.4 Comparisons and Conditional Branches
Nearly all programs need the ability to test their data and alter the sequence of
instructions to be executed based on the results. A simple example is the square-
root function,
x .If x is negative, the procedure gives an error message; otherwise
it computes the square root. A function sqrt has to test x and then branch, depend-
ing on whether it is negative or not.
A common method for doing so is to provide conditional branch instructions
that test some condition and branch to a particular memory address if the condition
is met. Sometimes a bit in the instruction indicates whether the branch is to occur
if the condition is met or not met, respectively. Often the target address is not
absolute, but relative to the current instruction.
The most common condition to be tested is whether a particular bit in the ma-
chine is 0 or not. If an instruction tests the sign bit of a number and branches to
LABEL if it is 1, the statements beginning at LABEL will be executed if the number
was negative, and the statements following the conditional branch will be executed
if it was 0 or positive.
Many machines have condition code bits that are used to indicate specific con-
ditions. For example, there may be an overflow bit that is set to 1 whenever an
arithmetic operation gives an incorrect result. By testing this bit, one checks for
overflow on the previous arithmetic operation, so that if an overflow occurred, a
branch can be made to an error routine and corrective action taken.
 
 
Search WWH ::




Custom Search