题解 | #移位运算与乘法#

移位运算与乘法

https://www.nowcoder.com/practice/1dd22852bcac42ce8f781737f84a3272

`timescale 1ns/1ns

module multi_sel(
  input [7:0]d ,
  input clk,
  input rst,
  output input_grant,
  output [10:0]out
  );
  //*************code***********//
  reg [10:0]out_reg = 11'd0;
  reg input_grant_reg = 1'd0;
  reg [7:0] din = 8'd0;
  reg [3:0]status = 4'd0;

  parameter Status_be = 4'd1; 
  parameter Status_x1 = 4'd2; 
  parameter Status_x3 = 4'd3; 
  parameter Status_x7 = 4'd4; 
  parameter Status_x8 = 4'd5; 
  parameter Status_end = 4'd6; 
  parameter Status_wait = 4'd7; 
  
  assign  out = out_reg;
  assign  input_grant = input_grant_reg;

  always @(posedge clk)
  begin
      if(rst==1'd0)
      begin
          status <= 4'd0;
          input_grant_reg <= 1'd0;
          out_reg <= 11'd0;
      end
  end
  
  always @(posedge rst)
  begin
      status <= Status_x1;
  end
 
  always @(posedge clk)
  begin
      case(status)  
      Status_x1: begin
          din <= d;
          out_reg <= d;
          input_grant_reg <= 1'd1;
          status <= Status_x3;
      end
      Status_x3: begin
          out_reg <= (din<<2) - din ;
          input_grant_reg <= 1'd0;
          status <= Status_x7;
      end    
      Status_x7: begin
          out_reg <= (din<<3) - din ;
          status <= Status_x8;
      end   
      Status_x8: begin
          out_reg <= din<<3;
          status <= Status_x1;
      end
      default:
      begin
        status <= Status_x1;        
      end
      endcase
  end
  
  //*************code***********//
  endmodule

全部评论
要不说的好好读题呢!
点赞 回复 分享
发布于 2023-04-10 16:50 天津

相关推荐

不对是145个人…嗯…&nbsp;大家都没发现秋招提前批来了嘛..笑死我了
牛客39712426...:投了也是浪费时间,之前投米实习,除了浪费我时间写笔试题没有任何反馈,懒得投了
26届校招投递进展
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-15 17:24
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务