串行乘法器
module serial8mult(clk, x, y, p);//8位串行乘法器
input clk;
input [7:0] x;
input [7:0] y;
output [15:0] p;//结果输出
reg[15:0]p;
parameter s0=0,s1=1,s2=2;
reg[2:0]cnt;//位数计数器
reg[1:0]state;//状态计数器
reg[15:0]p1,t;
reg[7:0]y_reg;
always@(posedge[/email] clk)begin
case(state)
s0:begin
y_reg<=y;
state<=s1;
cnt<=0;
p1<=0;
t<={{8{x[7]}},x};
end
s1:begin
if(cnt==7)
state<=s2;
else begin
if(y_reg[0]==1)
p1<=p1+t;
y_reg<=y_reg>>1;
t<=t<<1;
cnt<=cnt+1;
state<=s1;
end
end
s2:begin
p<=p1;
state<=s0;
end
endcase
end
endmodule
你用什么仿真?modelsim的话要加复位。否则state是高阻。
ISE的,x,y值都有,就是没有p
顶一下
你不给个波形图都看不出你的信号输入对不对
可否提供 testbench?
always #10 clk=!clk;
initial begin
// Initialize Inputs
clk = 0;
rst = 0;
x = 0;
y = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus herereset=1;
rst=1;
repeat (times)
begin
x=10+{$random}%50;y=13+{$random}%50;
$display("x=%d,y=%d",x,y);
end
end
A,B都有,就是结果是未知数,16‘hxxxx
首先你的代码风格不好,然后最好带点波形好看些。
從RTL上面來看,因為state這個訊號在電路初始化時,是沒有初始值的.....導致你的電路動作不正確
你可以藉由波形的觀測,判斷我的觀點是否正確

不晓得,会这么简单么
看不懂
