Guide to RISC Processors: For Programmers and Engineers

This chapter looks at the logical, shift and rotate instructions provided by MIPS. The MIPS instruction set provides four logical instructions: and, or, xor, and nor. There is no not instruction. This operation can be synthesized from the nor operation. We have introduced some of these instructions in Chapter 10. The logical instructions are useful to implement high-level language logical expressions. In addition, they can be used for bit manipulation. The shift and rotate instructions are useful in bit shift operations. We give several examples to illustrate the use of these instructions. We end the chapter with a summary.
As we have seen in the last chapter, high-level languages provide several conditional and loop constructs. These constructs require Boolean or logical expressions to specify conditions. In principle, only a single bit is needed to represent the Boolean data. However, such a representation, although compact, is not convenient, as testing a variable involves isolating the corresponding bit.
Most high-level languages use a byte to represent the Boolean data. If the byte is zero, it represents false; otherwise, true. Note that any value other than 0 can be used to represent true. In C, which does not provide an explicit Boolean data type, any data variable can be used in a logical expression to represent Boolean data. The rules mentioned above apply.
Assembly language provides several logical instructions, which are useful in implementing logical expressions of high-level languages. For example, C provides...