An ISE simulation of the above code is shown in Figure 1.
The simplified syntax of a “case” statement is given below: 1 case (control_expression) 2 option_1: 3 begin 4 Procedural_statement_1; 5 end 6 option_2: 7 begin 8 Procedural_statement_2; 9 end 10 ...
These can be used to specify don’t-care values when making comparisons to choose a branch. We’ll see that using “casex” and “casez” can make the description of certain structures, such as priority encoders, more compact. instead of explicitly mentioning all the possible values.
It’s important to note that the “casex” statement can mask out the bit locations that contain z or x values from either side of the comparison.
Lines 15 to 19 use an “if” statement to describe the “v” output as given in the truth table.
Assign Statement In Verilog
The condition checked within this “if” statement is defined using the Verilog bitwise OR operator.This article explains the use of Verilog “If” and “Case” statements to describe a combinational circuit.We’ll also take a look at the Verilog “Casex” and “Casez” statements and briefly discuss the potential pitfalls of using these two statements.A two-bit signal, “sel”, is used to choose the desired input and assign it to “out1”.The code for this example is as: 1 module Mux4_to_1( 2 input wire a, 3 input wire b, 4 input wire c, 5 input wire d, 6 input wire [1:0] sel, 7 output reg out1 8 ); 9 always @* 10 case (sel) 11 2'b00: 12 out1 = a; 13 2'b01: 14 out1 = b; 15 2'b10: 16 out1 = c; 17 default: 18 out1 = d; 19 endcase 20 endmodule When “sel”=00, the output is equal to “a”. Figure 2 shows an ISE simulation of the above code.The input with the highest priority (x) is checked first.If it’s logic high, the condition is evaluated as true and the output is set to 11.When describing a combinational circuit using an “always” block, we should list all of the inputs in the sensitivity list.Instead of listing all those inputs, we can simply use @* as used in Line 6 above.The following example clarifies this point: When “addr” is 001 or 011, “out” should be 00. What branch will be selected by the “casex” statement? 1 match x11 so the default branch should be chosen and "out" should be 00.However, as mentioned above, the bit locations that contain z or x values will be masked no matter they are in the branch expression or in the expression within the parentheses after the “casex” statement.