题解 | #位拆分与运算#

位拆分与运算

https://www.nowcoder.com/practice/1649582a755a4fabb9763d07e62a9752

`timescale 1ns/1ns

module data_cal(
input clk,
input rst,
input [15:0]d,
input [1:0]sel,

output [4:0]out,
output validout
);
//*************code***********//
reg [15:0]temp;
reg [4:0] t_out;
reg flag=1'b0,v_out;
always@(posedge clk or rst)
begin
if(!rst)
begin
v_out<=1'b0;
t_out<=1'b0;
end
else
begin
   if(sel==2'b00)
   begin
   v_out<=0; 
   t_out<=0;
   flag<=0;
   temp<=d;
   end
        else
        begin
         v_out<=1;
         flag<=1;  
         case(sel)
2'b01:begin t_out<=temp[3:0]+temp[7:4] ;end
2'b10:begin t_out<=temp[3:0]+temp[11:8] ;end
2'b11:begin t_out<=temp[3:0]+temp[15:12] ;end
default: begin t_out<=0;  end
endcase
 
        end
end
end










assign validout=v_out;
assign out=t_out;
//*************code***********//
endmodule

全部评论

相关推荐

2025-12-28 22:19
门头沟学院 Java
不敢追165女神:简历写得毫无特点,你说你要是大二或者大三找寒假实习到暑期实习这段时间,你的简历还能约到面试。但是你是研究生哥,面试官不会因为你是研究生而降低要求,反而会觉得你是研究生才学了这么一点?为什么我不找个同阶段的本科生?
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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