Chapter 2: Arithmetic Logic Unit Flashcards
What does the ALU do?
The ALU will perform an operation on its inputs to create a single output value.
Usually, there are two inputs and one destination. The flags in the status register may be affected by the operation. However, which operations affect which flags is processor dependent.
The two types of addition performed by ALU?
Addition simply takes the two inputs and adds them together. An “Add with carry” operation is usually included that adds the carry input as well.
This is used to enable multi-word operation. A new carry output is also produced. The same process applies to both signed and unsigned integers. However, if an overflow occurs, then you will know that the result will be incorrect if they were signed numbers.
How does the ALU subtract?
Subtraction simply takes the two inputs and subtracts one from the other. It is usually achieved by taking the one’s or two’s complement of one input and feeding the inputs to the adder.
A Subtract with carry operation is usually included that takes account of the carry/borrow bit
ALU comparison?
A compare simply takes the two inputs and subtracts one from the other. This is achieved in exactly the same way as a subtraction: Source A – Source B. There is no need for a destination since the flags provide the result:
- Zero – Values are the same
- Carry/Borrow (if a borrow has occurred, C=0, otherwise C=1), Negative and Overflow – Which is bigger
ALU Negate?
This create the two’s complement of a number. Simply works by using the subtractor with one of the inputs set to zero, so that it calculates 0 – number.
ALU Multiply with 2 numbers?
Multiplying two N bit numbers together produces a 2N bit result.
Sometimes the low and high parts of the result are stored in different registers.
ALU Multiply with 3 numbers
Sometimes a special multiply and add or MAC instruction is provided. In this case there are 3 sources and 2 destinations. This instruction is very useful for quick signal processing. However both the multiply and MAC instructions are often not available.
ALU Divide?
Division can produce a result and a remainder so that 2 destinations can be used. This operation is often not available.
ALU Logic?
- All the standard logic operations will normally be provided, such as AND, OR, NOT, XOR. They operate bitwise between the two sources.
- Another set of instructions can be used to test, set or clear individual bits. These are useful to test, set or clear flags.
ALU Shits?
Shifting takes a single source and moves all bits up or down the word. Shift left is equivalent to multiplying the number by 2, whereas shifting right is equivalent to dividing by 2.
For right shifts it is likely that sign extension is required to make sure the bit made vacant by the shift is correct. However often it is not available.
ALU Rotate?
Rotate left and right are similar to shift. However the bit moved off one end is used in the vacant space at the other. Rotate through the carry bit is sometimes also available. This instruction is useful for bit manipulation. However often it is not available.
ALU SIMD
(Single Instruction, Multiple Data)
This is a useful type of instruction for when the same operation is to be done on a large set of data points, such as increasing the brightness in an image or increasing the volume in a digital audio data file. They can speed up the performance of computers. These instructions are quite recent additions to microprocessor architectures, with their introduction driven strongly by video games and video processing.
Describe how flags can be used to determine the result of a compare operation between two unsigned integers in an ALU?