Lab 2
Lab 2
EXPERIMENT NO 2
Lab Title: Implementation of Half Adder and Full Adder and ALU
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
CODE:
module ALU(
input [7:0]A,
input [7:0]B,
input [2:0]op,
output [7:0]R);
reg [7:0]R;
always @(*)
begin
case(op)
3'b000: R = (A+B);
3'b001: R = (A-B);
3'b010: R = (A & B);
3'b011: R = ~(A|B);
3'b100: R = (A|B);
3'b101: R = ~(A&B);
3'b110: R = (A^B);
3'b111: R = ~(A);
endcase
end
endmodule
TB:
module ALUtb;
// Inputs
reg [7:0] A;
reg [7:0] B;
reg [2:0] op;
// Outputs
wire [7:0] R;
// Instantiate the Unit Under Test (UUT)
ALU uut (
.A(A),
.B(B),
.op(op),
.R(R)
);
initial begin
// Initialize Inputs
A = 8'b11001110;
B = 8'b01100101;
op = 000;
// Wait 100 ns for global reset to finish
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 001;
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 010;
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 011;
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 100;
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 101;
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 110;
#100;
A = 8'b11001110;
B = 8'b01100101;
op = 111;
// Add stimulus here
end
endmodule
Figure 1:: 3 Bits ALU
Sequential Block Code:
end
endmodule
Data Flow:
Code:
module fulladder(a,b,cin,sum,cout);
input a,b,cin;
output sum,cout;
assign {cout,sum} = a + b + cin;
endmodule
Behavioural:
Code:
module fabehaviour(a,b,cin,sum,cout);
input a,b,cin;
output sum,cout;
reg sum,cout;
always@(*)
begin
{cout,sum} = a+b+cin;
end
endmodule
GateLevel:
RTL:
Data Flow:
RTL:
Behavioural:
RTL:
Conclusion:
In this lab we have learnt how to use XILINX and implemented code of a 3-bits ALU, made a half
and full adder, also implemented sequential block code using (+ve edge clock, -ve edge reset) and
Structural Modeling. This foundational knowledge will be crucial for future exploration in
digital system design and integrated circuit development.