Logic Instructions (Microcontrollers)

2.3
Logic instructions (see Table 2.6) are used to set and clear individual bits in A, B, and CCR. They are used by compilers, programs that translate high-level languages to machine code, to manipulate bits to generate machine code. They are used by controllers of machinery because bits are used to turn things on and off. They are used by operating systems to control input-output (I/O) devices and to control the allocation of time and memory on a computer. Logic instructions are missing in calculators. That makes it hard to write compilers and operating systems for calculators, no matter how much memory they have. Returning to a problem at the end of topic 1, we now say a programmable calculator is not a von Neumann computer because it does not have logic instructions or any efficient replacements for these instructions with combinations of other instructions. (This differentiation may be pedagogically satisfying, but unfortunately, von Neumann’s original computer is not a von Neumann computer by this definition. Because we are engineers and not historians, we say that programmable calculators, and von Neumann’s original computer, are not von Neumann computers in the strictest sense because they cannot support compilers and operating systems efficiently.)
Consider now the logic instructions that make a computer a computer and not a calculator. The most important logic instructions carry out bit-by-bit logic operations on accumulators A or B with a memory location or an immediate value. (See Figure 2.10 for a summary of the common logic operations.) For example, the instruction ANDB $ 8 17 carries out a bit-by-bit AND with the contents of B and the contents of location $817, putting the result in B (see Figure 2.11b). The ANDing is implemented by AND gates in the MPU, shown in Figure 2.1 la. Compare to Figure 1.4d. The OR and AND instructions are used, among other things, to set or clear control bits in registers used in input-output operations.
The two instructions AN DA and ANDCC do the same thing as ANDB except that ANDCC uses only immediate addressing and the condition code register CCR. As an example, ANDCC #$FE clears the carry bit in the condition code register, that is, puts C = 0 leaving the other bits unchanged. This instruction is used only to clear condition code bits and is not used to modify other data bits. The same remarks hold for the OR instructions, ORAA, ORAB, and ORCC, and for the exclusive-OR instructions, EORA and EORB (see Figure 2.11a again: Exchange the AND gates with OR or exclusive-OR gates). The mnemonics CLC, CLI, SEC, SEI, SEV, CLV are merely special cases of the ANDCC and ORCC instructions; they are given these special mnemonic names to permit assembly-language programs written for the 6811 to be used without modification in the 6812. While the ANDCC instruction is used to clear bits in the CCR register, the ORCC instruction is used to set bits in that register. There is no EORCC instruction.
Common Logic Operations
Figure 2.10. Common Logic Operations
Table 2.6. Logic Instructions
 Logic Instructions
Consider this example. Suppose that we need to clear bits 0 and 4; set bits 5,6, and 7; and leave bits 1, 2, and 3 unmodified in accumulator A. The following instructions carry out these modifications.
tmp33-23_thumb Bit-by-Bit AND
Figure 2.11. Bit-by-Bit AND
Table 2.7. Edit Instructions
Edit Instructions
The complement instruction COM takes the complement of the bit-by-bit contents of A, B, or a memory location, putting the result in the same place. Finally, the BIT instruction, for bit test, determines the bits as though the AND instruction had been performed with A or B and the contents of a byte from memory. With the BIT instruction, however, the contents of A and B are unchanged. It is to the AND instruction what the CMP instruction is to the SUB instruction; it is used to avert the need to reload the register after the condition code bits are set as in the AND instruction.
Logic instructions are used primarily to set and clear and to test and change (logically invert) bits in a word. These instructions are used to build operating systems, compilers, and other programs that control resources and format data. These are the instructions that make a computer so much more useful than a programmable calculator.
Shifts and Rotates
Figure 2.12. Shifts and Rotates
 Shift Hardware
Figure 2.13. Shift Hardware


Next post:

Previous post: