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

移位运算与乘法

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 天津

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# AI面会问哪些问题? #
24847次浏览 491人参与
# 中国电信笔试 #
31080次浏览 283人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
14138次浏览 209人参与
# 你的实习产出是真实的还是包装的? #
18792次浏览 330人参与
# 如果秋招能重来,我会____ #
96691次浏览 500人参与
# 春招至今,你的战绩如何? #
59910次浏览 543人参与
# 厦门银行科技岗值不值得投 #
7490次浏览 186人参与
# i人适合做什么工作 #
36914次浏览 124人参与
# 我是面试官,请用一句话让我破防 #
79511次浏览 219人参与
# 哪些公司真双非友好? #
69200次浏览 287人参与
# 金三银四,你的春招进行到哪个阶段了? #
21567次浏览 277人参与
# 找AI工作可以去哪些公司? #
7673次浏览 186人参与
# 从事AI岗需要掌握哪些技术栈? #
7676次浏览 251人参与
# 投递几十家公司,到现在0offer,大家都一样吗 #
339915次浏览 2165人参与
# 面试尴尬现场 #
220755次浏览 861人参与
# 五一之后,实习真的很难找吗? #
102797次浏览 584人参与
# 你做过最难的笔试是哪家公司 #
30108次浏览 193人参与
# 你小时候最想从事什么职业 #
159840次浏览 2072人参与
# 应届生第一份工资要多少合适 #
20483次浏览 84人参与
# 阿里笔试 #
176460次浏览 1302人参与
# 一张图晒出你司的标语 #
3821次浏览 72人参与
# 面试被问期望薪资时该如何回答 #
382459次浏览 2163人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务