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。求助啊
不行啊,仿真结果一直是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.