CS Electrical And Electronics
@cselectricalandelectronics

Write a verilog code for half adder struct modelling?

All QuestionsCategory: VerilogWrite a verilog code for half adder struct modelling?
CS Electrical And Electronics Staff asked 4 years ago

I need code.

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

//HA STRUCT MODELLING

module HA(S,C,a,b);
input a,b;
output S,C;
xor (S,a,b);
and (C,a,b);
endmodule

//TB

module ha_tf;

// Inputs

reg a;
reg b;

// Outputs

wire S;
wire C;

// Instantiate the Unit Under Test (UUT)

HA uut (
.S(S),
.C(C),
.a(a),
.b(b)
);
initial begin

// Initialize Inputs

a = 0;
b = 0;

// Wait 100 ns for global reset to finish

#100;

// Add stimulus here

a=0;
b=1;
#100;
a=1;
b=0;
#100;
a=1;
b=1;
#100;

end

endmodule