Page 199 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 199
Unit 14: Interrupts
Increment and Decrement Notes
Two other instructions are included in the arithmetic group. They are increment and decrement.
These instructions are used to count events or loops in a program. Each time an increment is
executed, the value is incremented by 1. A decrement, decrements the value by 1. These can be
used with conditional jumps to loop a section of program, a certain number of times.
14.4.2 Logical
In micros there are other mathematical instructions called logical instructions. These are OR,
AND, XOR, ROTATE, COMPLEMENT and CLEAR. These commands are usually not concerned
with the value of the data they work with, but, instead, the value, or state, of each bit in the data.
OR
The OR function can be demonstrate by taking two binary numbers, 1010b and 0110b. When
OR'ing two numbers, it doesn't matter at which end you start, right or left. Let's start from the
left. In the first bit position there is a 1 in the first number and a 0 in the second number. This
would result in a 1. The next bit has a 0 in the first number and a 1 in the second number. The
result would be 1. The next bit has a 1 in the first number and a 1 in the second number. The result
would be a 1. The last bit has a 0 in the first number and a 0 in the second number, resulting in a
0. So the answer would be 1110b. The rule that gives this answer says that with an OR, a 1 in
either number result in a 1, or said another way, any 1 in, gives a 1 out.
AND
AND in uses a different rule. The rule here is a 0 in either number will result in a 0, for each
corresponding bit position. Using the same two numbers 1010b and 0110b the result would be
0010b. You can see that every bit position except the third has a zero in one or the other number.
Another way of defining an AND is to say that a 1 AND a 1 results in a 1.
XOR (Exclusive OR)
XOR'ing is similar to OR'ing with one exception. An OR can also be called an inclusive OR. This
means that a 1 in either number or both will result in a 1. An eXclusive OR says that if either
number has a 1 in it, but not both, a 1 will result. A seemingly small difference, but crucial. Using
the same two numbers, the result would be 1100b. The first two bits have a 1 in either the first or
the second number but not both. The third bit has a 1 in both numbers, which results in a 0. The
fourth has no 1's at all, so the result is 0. The difference may seem small, even though the OR and
XOR result in different answers. The main use of an XOR is to test two numbers against each
other. If they are the same, the result will be all 0's, otherwise the answer will have 1's where there
are differences.
14.4.3 Compliment
Complimenting a number results in the opposite state of all the 1's and 0's. Take the number
1111b. Complimenting results in 0000b. This is the simplest operator of all and the easiest to
understand. Its uses are varied.
14.4.4 Rotate
These instructions rotate bits in a byte. The rotation can be left or right, and is done one bit each
instruction. An example might be where the accumulator has a 11000011b in it. If we rotate left,
the result will be 10000111b. You can see that bit 7 has now been moved into bit 0 and all the other
bits have move 1 bit position in, the left direction
LOVELY PROFESSIONAL UNIVERSITY 193