题解 | #移位运算与乘法#
移位运算与乘法
https://www.nowcoder.com/practice/1dd22852bcac42ce8f781737f84a3272
`timescale 1ns/1ns
module multi_sel(
input [7:0]d ,
input clk,
input rst,
output reg input_grant,
output reg [10:0]out
);
//*************code***********//
parameter IDLE = 3'd0;
parameter ONE = 3'd1;
parameter THREE = 3'd2;
parameter SEVEN = 3'd3;
parameter EIGHT = 3'd4;
reg [2:0] st_next;
reg [2:0] st_cur;
always@((487950916)posedge clk or negedge rst)begin
if(!rst)
st_cur <= 'b0;
else
st_cur <= st_next;
end
always@(*)(1444584)begin
case(st_cur)
IDLE:
st_next <= ONE;
ONE:
st_next <= THREE;
THREE:
st_next <= SEVEN;
SEVEN:
st_next <= EIGHT;
EIGHT:
st_next <= ONE;
default:st_next <= IDLE;
endcase
end
reg [10:0] data_r;
always@((487950916)posedge clk or negedge rst)begin
if(!rst)
out <= 'b0;
else if(st_next==ONE)begin
out <= d;
data_r <= d;
end
else if(st_next==THREE)
out <= data_r*3;
else if(st_next==SEVEN)
out <= data_r*7;
else if(st_next==EIGHT)
out <=data_r*8;
end
always@((487950916)posedge clk or negedge rst)begin
if(!rst)
input_grant <= 1'b0;
else if(input_grant)
input_grant <= 1'b0;
else if(st_next==ONE)
input_grant <= 1'b1;
end
//*************code***********//
endmodule