VL4 移位运算与乘法
题目描述:
已知d为一个8位数,请在每个时钟周期分别输出该数乘1/3/7/8,并输出一个信号通知此时刻输入的d有效(d给出的信号的上升沿表示写入有效)

思路:每时每刻计算new_out,用时序逻辑赋值给out
`timescale 1ns/1ns
module multi_sel(
input [7:0]d ,
input clk,
input rst,
output reg input_grant,
output reg [10:0]out
);
//*************code***********//
reg [1:0] cnt ;
reg [10:0] new_out = 0;
reg [7:0] dt;
always @(posedge clk, negedge rst)
if(!rst ) out <= 0;
else
out <= new_out;
always @(posedge clk)
if(!rst) cnt <= 0;
else begin
if (cnt == 2'b11) cnt <= 0;
else cnt <= cnt +1'b1;
end
always @(* )begin
if(!rst) dt = 0;
else
dt = (cnt == 0)?d : dt;
end
always @(* )begin
case(cnt)
2'b00: new_out = dt;
2'b01: new_out = dt* 2'd3;
2'b10: new_out = dt * 3'd7;
2'b11: new_out = dt * 4'd8;
default: new_out = 0;
endcase
end
always @(* )begin
input_grant = (rst)&(cnt == 1'd1);
end
//*************code***********//
endmodule
其中,input_grant也可以这样:
always @(posedge clk , negedge rst )begin
input_grant <= (rst)&(cnt == 1'd0);
end
703

被折叠的 条评论
为什么被折叠?



