ALU 4 Bit Verilog
ALU 4 Bit Verilog
ALU 4 Bit Verilog
- Result of the design process must a logic circuit that can implement in
reality with minimum of hardware resource
3. Procedures
- In a simple ALU consist of 2 modules: AU ( Arithmetic Unit) and LU
( Logic Unit) so we can split the ALU into two parts to design and
then using a MUX 2:1 for the output.
A adder = A (S 0 . S1 )
B adder =S0 . S 1 . B+
S1 . B
Therere a lot of way to make a Logic Unit, for simple and reduce the
amout of transistor needed, I made a truth table for 1-bit ALU with
opcodes S0,S1 correspondingly:
S0 S1 A B LU_out Note
0 0 0 0 0
0 0 0 1 0 AND
0 0 1 0 0
0 0 1 1 1
0 1 0 0 0
0 1 0 1 1 OR
0 1 1 0 1
0 1 1 1 1
1 0 0 0 0
1 0 0 1 1 XOR
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 0 XNOR
1 1 1 0 0
1 1 1 1 1
LU out =S1 ( S 0 ( A+ B )) + AB ( S0 + S 1) + S 0 S1 ( A B)
endmodule
/* 1-bit LU function */
module LU_1bit ( F0, S0, S1, Ai, Bi);
output F0 ;
input S0, S1, Ai, Bi ;
assign F0 = (S1 & (S0 ^ ( Ai | Bi ) ) ) |
((Ai & Bi ) & ( ~S0 | S1) ) |
((S0 & ~S1 ) & ( Ai ^ Bi )) ;
Endmodule
3.3 Design a 4 bit Mux 2:1
According to two above designed module ( AU and LU), both of AU and
LU will work concurently because is not depend on M ( bit-select). So,
we have to buid a Mux 2:1 to choose the output that we expected.
The idea is we will buid a 4 modules Mux 2:1 bit for 4 bit inout with
common bit select (M).
Mux 2:1 :
Code:
module mux2to1_4bit( F , A, B, M) ;
output [3:0] F ;
input [3:0] A, B ;
input M ;
initial
begin
opcode = 3'b000 ; A = 4'd12 ; B = 4'd9 ; c_in =1'b0 ;
//AND
#50 opcode = 3'b001 ; A = 4'd8 ; B = 4'd5 ; c_in =1'b0 ; //OR
#50 opcode = 3'b010 ; A = 4'd7 ; B = 4'd6 ; c_in =1'b0 ; //XOR
#50 opcode = 3'b011 ; A = 4'd8 ; B = 4'd5 ; c_in =1'b0 ;
//XNOR
#50 opcode = 3'b100 ; A = 4'd7 ; B = 4'd4 ; c_in =1'b0 ; //A+C
#50 opcode = 3'b101 ; A = 4'd2 ; B = 4'd9 ; c_in =1'b1 ;
//A+B+C
#50 opcode = 3'b110 ; A = 4'd15; B = 4'd9 ; c_in =1'b0 ;
//A+'B+C
#50 opcode = 3'b111 ; A = 4'd2 ; B = 4'd13 ; c_in =1'b1 ;
//'A+B+C
end
endmodule
Waveforms result:
So, according to the result of simulation wave-form,wee see that the ALU has
worked correctly. All of results as we expected.
4. Conclusion & Discussion
- The Lab has finished with correct results.
- The ALU is an important part of every CPU. I learnt how to produre
different arithmetic and logic function by divide it into smaller parts
and then design one by one from idea to logic gate and then test the
idea with Verilog HDL and simulate with ModelSim.
- Actually, the design in my lab above is not the best way to make a
ALU. For instance, we can use the full-adder with carry look-ahead
instead of ripple full-adder for the best performative
- The lab helped me review and enhance my poor knowledge about
digital design. Its very interesting and Im gonna study harder for
this.