verilog hdl 求助一个8位移位寄存器。。不知道怎么回事,总是没对

module yiweijicun(in,out,clk,rst);
input [7:0] in;
input clk,rst;
output [7:0] out;
reg [7:0] out;
reg [7:0] temp;
integer i=0;
always @(posedge clk)
begin
if (!rst)
out=0;
else
begin
temp=in;
out=(out<<1);
out[0]=temp[7];
temp=(temp<<i+1);
i=i+1;
end
end
endmodule

用in=10011101测试时,输出为11111111。求助啊

integer i=0;
也就是i是32位的,你要做8位的,那么i=i+1;应该累加8次就把数据输出,这点没有体现,i是32位的那么不设限制的话也就是i会累加32次才回到初始
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-10-08
module yiweijicun(in,out,clk,rst);
input [7:0] in;
input clk,rst;
output [7:0] out;
reg [7:0] out;
reg [7:0] temp;

always @(posedge clk)

begin
if (!rst)
out=0;
else
begin if(load)
temp=in;
else begin
out=(out<<1);
out[0]=temp[7];
end
end
end
endmodule追问

不行啊,仿真结果一直是00000000,再说了,你这个temp赋值in,而out的最低位始终是赋的temp,也就是in的最高位,那怎么实现把in全部赋给out呢?

追答

module yiweijicun(in,out,clk,rst);
input [7:0] in;
input clk,rst,load;
output out;
reg out;
reg [7:0] temp;

always @(posedge clk)

begin
if (!rst)
out=0;
else begin
if(!load)
temp=in;
else begin
out=temp[7];
temp[7]=temp[6];
temp[6]=temp[5];
temp[5]=temp[4];
temp[4]=temp[3];
temp[3]=temp[2];
temp[2]=temp[1];
temp[1]=temp[0];
end
end
end

When writing testbench,Set load low first.

本回答被提问者采纳
相似回答