题解 | #三元操作符#
三元操作符
https://www.nowcoder.com/practice/460dd32658f1402382f9a3a65a577a85
`timescale 1ns/1ns module top_module( input [7:0] a, b, c, d, output [7:0] max);// //俩俩对比 wire [7:0] flag1,flag2; assign flag1 = (a>=b)?a:b; assign flag2 = (c>=d)?c:d; assign max = (flag1 >= flag2)?flag1:flag2; endmodule
//使用循环 reg [7:0][3:0]buff; reg [7:0]temp; integer i; always @(*)begin buff[0] = a; buff[1] = b; buff[2] = c; buff[3] = d; temp=buff[0]; for(i=0;i<4;i=i+1)begin:a1 temp = temp > buff[i]?temp:buff[i]; end end