Professional Documents
Culture Documents
ID EST 0735-08 Mathewos Budusa
ID EST 0735-08 Mathewos Budusa
Prepared by:
Mathewos Budusa………………………………………….0735/08
subtractor
module sub_32_bits(diff,a,b);
input [31:0]a,b;
output [31:0]diff;
assign diff=a-b;
endmodule
/////////////////////////
module test_sub_32_bits;
reg [31:0]a,b;
wire [31:0]diff;
sub_32_bits sub(diff,a,b);
initial #500 $finish;
initial
begin
a=32'd1;
end
initial
repeat(31)
begin
#10;
a=32'b00000000000000000000000000011000;
b=32'b00000000000000000000000000000100;
#10;
a=32'b00000000000000000000000000001111;
b=32'b00000000000000000000000000000111;
#10;
a=32'b00000000000000000000000001011001;
b=32'b00000000000000000000000000000000;
#10;
a=32'b00000000000000000001001000000001;
b=32'b00000000000000000000011000000000;
#10;
a=32'b00000000000000000001010000000001;
b=32'b00000000000000000000010000000000;
end
endmodule
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
module encoder(i, e);
input [3:0] i;
output [1:0] e;
assign e=(i == 4'b0001)?2'b00:((i==4'b0010)?2'b01:
((i == 4'b00100)?2'b10:
((i == 4'b1000)?2'b11:2'bxx)));
/*always @(i)
begin
if (i == 4'b0001) e = 2'b00;
else if (i == 4'b0010) e = 2'b01;
else if (i == 4'b0100) e = 2'b10;
else if (i == 4'b1000) e = 2'b11;
else e = 2'bxx;
end */
endmodule
//////////////////////////////////////////////////////////////////////////////////
module test_encoder;
reg [3:0]i;
wire [1:0]e;
encoder enc(i,e);
initial
begin
i=4'b0000;
end
initial
begin
#10;
i=4'b0001;
#10;
i=4'b0010;
#10;
i=4'b0100;
#10;
i=4'b1000;
end
endmodule
//////////////////////////////////////////////////////////////////////////////////
module Adder_32_bit(sum,cout,cin,a,b);
input [31:0]a,b;
input cin;
output [31:0]sum;
output cout;
assign {cout,sum}=a+b+cin;
endmodule
/////////////////////////////////////////////////////////////////////////////////
module test_adder_32_bit;
reg [31:0]a,b;
reg cin;
wire [31:0]sum;
wire cout;
Adder_32_bit add(sum,cout,cin,a,b);
initial
#500
$finish;
initial
begin
cin=1'b0;
a=32'd0;
b=32'd1;
end
initial
repeat(31)
begin
#10;
a=a+32'd1;
b=b+32'd1;
end
endmodule