if else形式
if else 形式写的代码会被EDA软件综合为多路选择器,无优先级顺序。
/*
* @Author: yaohao
* @Date: 2022-11-21 15:22:20
* @Last Modified by: yaohao
* @Last Modified time: 2022-11-21 15:49:56
*/
module sys_pp (
input wire a,
input wire b,
input wire c,
input wire sel0,
input wire sel1,
input wire sel2,
output wire res
);
always @(*) begin
res = 0;
if (sel2) begin
res = c;
end
else if (sel1) begin
res = b;
end
else if (sel0) begin
res = a;
end
//多if形式
/*
if (sel0) begin
res = a;
end
if (sel1) begin
res = b;
end
if (sel2) begin
res = c;
end
*/
end
endmodule
多if形式
多if写的代码会综合成带优先级的电路,如下图所示,最后一级为最高优先级。
/*
* @Author: yaohao
* @Date: 2022-11-21 15:22:20
* @Last Modified by: yaohao
* @Last Modified time: 2022-11-21 15:32:10
*/
module sys_pp (
input wire a,
input wire b,
input wire c,
input wire sel0,
input wire sel1,
input wire sel2,
output wire res
);
always @(*) begin
res = 0;
if (sel0) begin
res = a;
end
if (sel1) begin
res = b;
end
if (sel2) begin
res = c;
end
end
endmodule