131 Week 4 - Arithmetic Logic Unit Flashcards
Role of the arithmetic logic unit (ALU)
Implements arithmetic (add, subtract, shifts etc) and logic operations (and, or, not, xor; comparisons - < = > etc.)
What does the ALU provide
Registers and status flags
Half adder
A logic circuit for adding 2 bits and returning a sum bit and carry bit.
XOR for sum and AND for carry.
Full adder
A logic circuit for adding 3 bits (2 inputs and 1 carry input) and returning a sum bit and carry out bit.
Ripple carry adder
Full adders can be connected together by linking C out of previous adder and C in of current adder allowing them to add multi bit numbers.
Disadvantage of ripple carry adder
They are slow because each full adder relies on the C out of the previous adder meaning each adder has to be executed one after another.
Carry select adder
Connects carry bits of adders similar to a ripple carry adder.
Lower half of the bits are added like a ripple carry adder.
Upper half of the adder is added twice, once assuming the first C in is 0 and another assuming it is 1.
After the lower half of the bits has been added, the correct prediction of the upper half of the bits is selected and an output is returned.
Advantages of a carry select adder
Because all 3 additions can be executed in parallel, a carry select adder is effectively twice as fast as a ripple carry adder.
Status flag
Bits organised into a special register called the flags register.
Each flag reflects an aspect of the result of an ALU operation.
Zero flag
Checks if an output results in 0.
Works by using a NOR gate on the result of an operation:
If any of the results of an ALU operation is 1, the zero flag is 0.
If all results of an ALU operation is 0, the zero flag is 1
Negative flag
Checks if an output results in a negative number.
Works by checking if the leftmost bit is 1 or 0:
If it is 1, the number is negative.
If it is 0, the number is positive.
Overflow flag
Checks if an output has resulted in an overflow error.
Works by checking signs of the inputs and the result.
If positive + positive = negative or negative + negative = positive, an overflow error has occurred.
Logic circuit for overflow flag
C in XOR C out
Bit shifting
A bit shift left or right works as multiplying or dividing by a power of 2 respectively.
4 types of shifts
arithmetic shift, logical shift, rotate and rotate through carry