A simple ALU
Contents
A simple ALU#
What is an arithmetic logic unit?
Solution to Exercise 152
It is a circuit which can carry arithmetic and logical operations like:
addition
comparison
bitwise shift.
ALU is used in CPUs.
Learning Goals#
Understand how ALUs function
Be able to describe a simple ALU in Verilog
Background#
Arithmetic Logic Unit (ALU)#
An ALU is controlled by some control signals.
How are these control signals called?
What do these control signals consist of?
Where do these control signals come from?
Solution to Exercise 153
opcode
An opcode consists of an operation and operand/s, e.g., compare a with b.
Opcodes are embedded in a compiled program as binary. They can also be recognized in assembly as mnemonics.
Imagine you have an 8 bit ALU with following operations:
Opcode 
Operation 

0 
No operation 
1 
Add 
2 
Subtract 
3 
Increment 
4 
Bitwise Inverse 
5 
Bitwise XOR 
6 
Bitwise OR 
7 
Bitwise AND 
Design the bit slice circuits for this ALU.
How would the behavioral design for the operations look like?
Solution to Exercise 154
1. Structural bit slice design
We already designed addition and subtraction bit slices in previous chapters.
The bit slice has the inputs:
input operands:
a
,b
carry input:
ci
and the outputs:
result:
r
carry output:
co
The following table shows the equations for the bit slice:
Opcode 
Operation 
Bitslice, 
Remarks 

0 
No operation 


1 
Add 

for carry, two signals active 
2 
Subtract 

similar to addition, but 
3 
Increment 

addition with b=1 
4 
Bitwise Inverse 


5 
Bitwise XOR 


6 
Bitwise OR 


7 
Bitwise AND 

Additionally we have to include a multiplexer which selects the corresponding operation depending on the 3 bit opcode.
2. Behavioral design
In behavioral design we leave the implementation to the synthesizer. We only have to describe these operations using Verilog syntax. This has the advantage that we can conveniently describe the function for the whole byte without paying attention to the carry bits.
Opcode 
Operation 
Result byte 

0 
No operation 

1 
Add 

2 
Subtract 

3 
Increment 

4 
Bitwise Inverse 

5 
Bitwise XOR 

6 
Bitwise OR 

7 
Bitwise AND 

Requirements#
TODO