Sie sind auf Seite 1von 1

module alu(a,b,sel,out);

input [3:0] a,b;


input [2:0] sel;
output [3:0] out;
reg [3:0] out;
always@(a,b) begin
case(sel)
3'b000:
3'b001:
3'b010:
3'b011:
3'b100:
3'b101:
3'b110:
3'b111:
endcase
end
endmodule

out
out
out
out
out
out
out
out

=
=
=
=
=
=
=
=

a +
a +
a a a &
a |
a ^
~(a

b;
b+1;
b;
b-1;
b;
b;
b;
+ b);

module alu_tb;
reg [3:0] a,b;
reg [2:0] sel;
wire [3:0] out;
reg [3:0] out1;
alu alu0(a,b,sel,out);
initial begin
repeat(20) begin
a = $random;
b = $random;
sel = $random;
case(sel)
3'b000:
play("Success") end;
3'b001:
isplay("Success") end;
3'b010:
splay("Success") end;
3'b011:
display("Success") end;
3'b100:
splay("Success") end;
3'b101:
splay("Success") end;
3'b110:
splay("Success") end;
3'b111:
$display("Success") end;
endcase
end
end
endmodule

begin out1 = a + b; if(out == out1) $dis


begin out1 = a + b+1; if(out == out1) $d
begin out1 = a - b; if(out == out1) $di
begin out1 = a - b-1; if(out == out1) $
begin out1 = a & b; if(out == out1) $di
begin out1 = a | b; if(out == out1) $di
begin out1 = a ^ b; if(out == out1) $di
begin out1 = ~(a + b); if(out == out1)

Das könnte Ihnen auch gefallen