移位寄存器 verilog代码

来源:百度知道 编辑:UC知道 时间:2024/06/17 14:14:46
求一个移位寄存器 verilog代码要求输入输出端口如下
input in,clk,en,clr,set;
output out;
异步清零同步置位带使能
写出来的编译通过+100分!

//这个程序串行输入,并行8位输出

module yiwei(in,clk,en,clr,set,out);
input en,set,clk,clr;
input in;
output [7:0] out;
reg [7:0] out;

always@(posedge clk or negedge clr)
begin
if(!clr)//异步清零
begin
out<=0;
end

else
begin
if(en & set) out<=8'b11111111;//置位

else if(en)//使能
begin
out<=out<<1;
out[0]<=in;
end

else
out<=out;
end
end

endmodule

module shift(
in,
clk,
en,
clr,
set,
out
);
input [7:0]in; //input data
input clk; //input clock
input en; //input enable high enable
input clr; //input clear low enable
input [2:0]set; //input set :set num of shift bit
output [7:0]out;

always@(posedge clk or negedge clr) begin: shift_reg
if(!clr) //asychro reset_n low enable
out <= 8'b