`define ORDER
module test;
reg [2:0]sel;
logic [2:0] values[9];
reg select;
`ifdef ORDER
always@(select)
begin
casex(select)
1'b?:$display("CASEZ :: LOGIC Z on select");
1'b0:$display("CASEZ :: LOGIC 0 on select");
1'b1:$display("CASEZ :: LOGIC 1 on select");
endcase
end
`else
always@(select)
begin
casex(select)
1'b1:$display("CASEZ :: LOGIC 1 on select");
1'b0:$display("CASEZ :: LOGIC 0 on select");
1'b?:$display("CASEZ :: LOGIC z on select");
endcase
end
`endif
initial begin
values={3'b00x,3'b0x0,3'bxx0,3'b0zx,3'bz0x,3'bxxz,3'bzz0,3'b10z,3'b111};
$display("select=z");
select=1'bz;#1;
$display("select=1");
select=1;#1;
$display("select=0");
select=0;#1;
$display("select=z");
select=1'bz;#1;
$display("select=x");
select=1'bx;#1;
$display("\n\n");
task_call();
end
task task_call();
$display("---------------CASE------------------------");
$display("Without don't cares in case");
$display("---------------CASE-----------------------");
for(int i=0;i<8;i++)
begin
case_call(i);
#5;
end
$display("\n\n");
$display("--------------CASE------------------------");
$display("With don't cares in case");
$display("--------------CASE------------------------");
for(int i=0;i<8;i++)
begin
case_call(values[i]);
#5;
end
$display("\n\n");
$display("----------------CASEX-----------------------");
$display("Without don't cares in case");
$display("----------------CASEX-----------------------");
for(int i=0;i<8;i++)
begin
casex_call(i);
#5;
end
$display("\n\n");
$display("------------------CASEX-------------------");
$display("With don't cares in case");
$display("------------------CASEX-------------------");
for(int i=0;i<8;i++)
begin
casex_call(values[i]);
#5;
end
$display("\n\n");
$display("----------------CASEZ-----------------------");
$display("Without don't cares in case");
$display("----------------CASEZ-----------------------");
for(int i=0;i<8;i++)
begin
casez_call(i);
#5;
end
$display("\n\n");
$display("------------------CASEZ-------------------");
$display("With don't cares in case");
$display("------------------CASEZ-------------------");
for(int i=0;i<8;i++)
begin
casez_call(values[i]);
#5;
end
endtask
function void case_call(reg [2:0] sel);
case(sel)
3'b000:$display("CASE :: sel=%3b || 3'b000",sel);
3'b001:$display("CASE :: sel=%3b || 3'b001",sel);
3'b010:$display("CASE :: sel=%3b || 3'b010",sel);
3'b011:$display("CASE :: sel=%3b || 3'b011",sel);
3'b100:$display("CASE :: sel=%3b || 3'b100",sel);
3'b101:$display("CASE :: sel=%3b || 3'b101",sel);
3'b110:$display("CASE :: sel=%3b || 3'b110",sel);
3'b111:$display("CASE :: sel=%3b || 3'b111",sel);
default:$display("CASE :: sel=%3b default",sel);
endcase
endfunction
function void casex_call(reg [2:0] sel);
casex(sel)
3'b00?:$display("CASEX :: sel=%3b || 3'b00?",sel);
3'b0?0:$display("CASEX :: sel=%3b || 3'b0?0",sel);
3'b?00:$display("CASEX :: sel=%3b || 3'b?00",sel);
3'b?0?:$display("CASEX :: sel=%3b || 3'b?0?",sel);
default:$display("CASEX :: sel=%3b || default",sel);
endcase
endfunction
function void casez_call(reg [2:0] sel);
casez(sel)
3'b00?:$display("CASEZ :: sel=%3b || 3'b00?",sel);
3'b0?0:$display("CASEZ :: sel=%3b || 3'b0?0",sel);
3'b?00:$display("CASEZ :: sel=%3b || 3'b?00",sel);
3'b?0?:$display("CASEZ :: sel=%3b || 3'b?0?",sel);
default:$display("CASEZ :: sel=%3b || default",sel);
endcase
endfunction
endmodule
/* OUTPUT
select=z
CASEZ :: LOGIC Z on select
select=1
CASEZ :: LOGIC Z on select
select=0
CASEZ :: LOGIC Z on select
select=z
CASEZ :: LOGIC Z on select
select=x
CASEZ :: LOGIC Z on select
---------------CASE------------------------
Without don't cares in case
---------------CASE-----------------------
CASE :: sel=000 || 3'b000
CASE :: sel=001 || 3'b001
CASE :: sel=010 || 3'b010
CASE :: sel=011 || 3'b011
CASE :: sel=100 || 3'b100
CASE :: sel=101 || 3'b101
CASE :: sel=110 || 3'b110
CASE :: sel=111 || 3'b111
--------------CASE------------------------
With don't cares in case
--------------CASE------------------------
CASE :: sel=00x default
CASE :: sel=0x0 default
CASE :: sel=xx0 default
CASE :: sel=0zx default
CASE :: sel=z0x default
CASE :: sel=xxz default
CASE :: sel=zz0 default
CASE :: sel=10z default
----------------CASEX-----------------------
Without don't cares in case
----------------CASEX-----------------------
CASEX :: sel=000 || 3'b00?
CASEX :: sel=001 || 3'b00?
CASEX :: sel=010 || 3'b0?0
CASEX :: sel=011 || default
CASEX :: sel=100 || 3'b?00
CASEX :: sel=101 || 3'b?0?
CASEX :: sel=110 || default
CASEX :: sel=111 || default
------------------CASEX-------------------
With don't cares in case
------------------CASEX-------------------
CASEX :: sel=00x || 3'b00?
CASEX :: sel=0x0 || 3'b00?
CASEX :: sel=xx0 || 3'b00?
CASEX :: sel=0zx || 3'b00?
CASEX :: sel=z0x || 3'b00?
CASEX :: sel=xxz || 3'b00?
CASEX :: sel=zz0 || 3'b00?
CASEX :: sel=10z || 3'b?00
----------------CASEZ-----------------------
Without don't cares in case
----------------CASEZ-----------------------
CASEZ :: sel=000 || 3'b00?
CASEZ :: sel=001 || 3'b00?
CASEZ :: sel=010 || 3'b0?0
CASEZ :: sel=011 || default
CASEZ :: sel=100 || 3'b?00
CASEZ :: sel=101 || 3'b?0?
CASEZ :: sel=110 || default
CASEZ :: sel=111 || default
------------------CASEZ-------------------
With don't cares in case
------------------CASEZ-------------------
CASEZ :: sel=00x || 3'b00?
CASEZ :: sel=0x0 || 3'b0?0
CASEZ :: sel=xx0 || default
CASEZ :: sel=0zx || 3'b00?
CASEZ :: sel=z0x || 3'b00?
CASEZ :: sel=xxz || default
CASEZ :: sel=zz0 || 3'b00?
CASEZ :: sel=10z || 3'b?00
V C S S i m u l a t i o n R e p o r t
*/