`timescale 1 ns/1 ns
module EX_205 (a, f);
input [2:0] a;
output [3:0] f;
reg [3:0] f;
// non-behavioral writing style in EX_107 is also listed for
// comparison. f should be declared as wire in non-behavioral
// writing style.
//
// wire [3:0] f;
//
// assign f = ( a==3'b000 ) ? 4'b1001 :
// ( a==3'b001 ) ? 4'b1010 :
// ( a==3'b010 ) ? 4'b0110 :
// ( a==3'b011 ) ? 4'b0000 :
// ( a==3'b100 ) ? 4'b0100 :
// ( a==3'b101 ) ? 4'b0001 :
// ( a==3'b110 ) ? 4'b0000 : 4'b1110 ;
always@( a )
begin
case (a)
3'b000 : f = 4'b1001;
3'b001 : f = 4'b1010;
3'b010 : f = 4'b0110;
3'b011 : f = 4'b0000;
3'b100 : f = 4'b0100;
3'b101 : f = 4'b0001;
3'b110 : f = 4'b0000;
default : f = 4'b1110;
endcase
end
endmodule
`timescale 100 ns/1 ns
module testbench;
reg [2:0] a;
wire[3:0] f;
integer i;
EX_205 UUT (.a(a), .f(f) );
initial begin
for (i=0;i<=7;i=i+1) begin
{a}=i;
#20;
end
#20;
$stop;
end
endmodule
沒有留言:
張貼留言