o = s ? a : b;
与逻辑:
out = (a == 1’b0)? 1’b0: ((b == 1’b0)? 1’b0: 1’b1);
或
out = (a == 1’b1)? b: 1’b0;
Y=SA+S’B=AB+A’0=AB
或逻辑:
out = (a == 1’b1)? 1’b1: ((b == 1’b1)? 1’b1: 1’b0);
或
out = (a == 1’b0)? b: 1’b1;
Y=SA+S’B=A’B+A=A+B
非逻辑:
out = (a == 1’b1)? 1’b0: 1’b1;
异或
out = (a == 1’b1)? ((b == 1’b1)? 1’b0: 1’b1) : (b);
Y=AB’+A’B
module mux
#(
parameter m = 8,
parameter n = 8,
parameter width = clogb2(n)
)
(
input [n*m-1:0] indata,
input [width-1:0] sel,
output [m-1:0] outdata
);
assign outdata = indata[(m*(sel+1)-1)-:m];
//-------------------------------------------------------
//以下两个函数任用一个
//求2的对数函数
function integer log2;
input integer value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
//求2的对数函数
function integer clogb2 (input integer bit_depth);
begin
for(clogb2=0; bit_depth>0; clogb2=clogb2+1)
bit_depth = bit_depth>>1;
end
endfunction
endmodule
function integer log2(input integer x);
integer i;
begin
log2 = 1;
for (i = 0; 2**i < x; i = i + 1) //不用移位寄存器,只用比较器
begin
log2 = i + 1;
end
end
endfunction
没有回复内容