如何用task呼叫
module mux(Din,S,Y);
input Din;
input [1:0]S;
output[3:0]Y;
reg [3:0]Y;
reg [1:0]X;
always@(Din or S) begin
X=demul2(S[1],Din);
Y[1:0]=demul2(S[0],X[0]);
Y[3:2]=demul2(S[0],X[1]);
end
function [1:0] demul2;
input S;
input D;
case(S)
1'b0: demul2={1'b0,D};
1'b1: demul2={D,1'b0};
default :demul2={1'b0,1'b0};
endcase
endfunction
endmodule
书中自有千钟粟
书中自有黄金屋
书中自有颜如玉
书中车马多簇簇
我就是看書上寫的 跑出來一直都有問題
task demul2;
input S;
input D;
output[1:0] Y;
case(S)
1'b0: Y={1'b0,D};
1'b1: Y={D,1'b0};
default :Y={1'b0,1'b0};
endcase
endtask
demul2( S[0],X[0],Y[1:0]);
demul2( S[0],X[1],Y[3:2]);
輸出Y的部份依舊是x 跑不出東西
我也就大致一写,你也稍微改一下撒....
wire[3:0] Y;
assign Y={1'b0,D};
还有,你的D都没有赋值,能出来东西就怪了
我還有加一點東西
你說的Y那部分我ㄧ開始就改過了
這是我全部的code 上面的是testfile
`timescale 1ns/1ps
module top;
reg Din=1;
reg [1:0]s;
wire [3:0]y;
initial begin
#20 s=2'b00;
#30 s=2'b01;
#40 s=2'b10;
#20 s=2'b11;
#100 $finish;
end
mux uut(
Din,
s,
y
);
endmodule
module mux (Din,s,y);
input Din;
input [1:0]s;
output [3:0]y;
reg [1:0]x;
reg [3:0]y;
always @( s) begin
demu12(s[0],x[0],y[1:0]);
demu12(s[0],x[1],y[3:2]);
end
task demu12;
input s;
input D;
output [3:0]y;
case (s)
1'b0: y={1'b0,D};
1'b1: y={D,1'b0};
default: y={1'b0,1'b0};
endcase
endtask
endmodule
x是啥东西?
说了是wire[3:0] y;
说了是assign y =...;
我知道您的意思 但Y是4bit
assign Y={0,D}不是只有2bit? 我還真有點搞混
我才學不到兩個禮拜 希望您多指導 謝謝
而x是做為選擇 看輸出是y[0],y[1]或者y[2],y[3]
assign y[1:0]
x由谁驱动呢?
我寫的是一對二mux 再加上兩個一對二mux 所以輸出是四個bit
我最後用了兩個task才完成
請小编看看 可能是我之前想寫什麼沒跟您說清楚 造成你的誤解吧
module mux (Din,s,y);
input Din;
input [1:0]s;
output [3:0]y;
reg [1:0]x;
reg [3:0]y;
always@(s) begin
mul2(Din,s[1],x[1:0]);
end
task mul2;
input D;
input S;
output [1:0]y;
case (S)
1'b0: y={1'b0,D};
1'b1: y={D,1'b0};
default: y={1'b0,1'b0};
endcase
endtask
always @(s or x) begin
demu12(x[0],s[0],y[1:0]);
demu12(x[1],s[0],y[3:2]);
end
task demu12;
input D;
input Si;
output [1:0]y;
case (Si )
1'b0: y={1'b0,D};
1'b1: y={D,1'b0};
default: y={1'b0,1'b0};
endcase
endtask
endmodule
