conditional ternary operator
Verilog has a ternary conditional operator ( ? : ) much like C: (condition ? if_true : if_false) This can be used to choose one of two values based on condition (a mux!) on one line, without using an if-then inside a combinational always block.
Conditional - HDLBits (01xz.net)
1 module top_module ( 2 input [7:0] a, b, c, d, 3 output [7:0] min);// 4 assign min = (a<b) ? 5 ((a<c) ? ((a<d) ? a:d) : ((c<d)? c:d)): 6 ((b<c) ? ((b<d) ? b:d) : ((c<d)?c:d)); 7 //没看懂 8 // assign intermediate_result1 = compare? true: false; 9 10 endmodule
再写:
怎么说呢,这种多嵌套的三目运算写是没啥问题,但是容易晕
module top_module (
input [7:0] a, b, c, d,
output [7:0] min);//
wire [7:0]m1;
wire [7:0]m2;
assign m1=(a>b)?b:a;
assign m2=(m1>c)?c:m1;
assign min=(m2>d)?d:m2;
// assign intermediate_result1 = compare? true: false;
endmodule

浙公网安备 33010602011771号