LV6_多功能數(shù)據(jù)處理器
題目來(lái)源于??途W(wǎng)
[??途W(wǎng)在線編程_Verilog篇_Verilog快速入門 (nowcoder.com)](https://www.nowcoder.com/exam/oj?page=1&tab=Verilog篇&topicId=301)
題目
描述
根據(jù)指示信號(hào)select的不同,對(duì)輸入信號(hào)a,b實(shí)現(xiàn)不同的運(yùn)算。輸入信號(hào)a,b為8bit有符號(hào)數(shù),當(dāng)select信號(hào)為0,輸出a;當(dāng)select信號(hào)為1,輸出b;當(dāng)select信號(hào)為2,輸出a+b;當(dāng)select信號(hào)為3,輸出a-b.
接口信號(hào)圖如下:
輸入描述:
clk:系統(tǒng)時(shí)鐘
rst_n:復(fù)位信號(hào),低電平有效
a,b:8bit位寬的有符號(hào)數(shù)
select:2bit位寬的無(wú)符號(hào)數(shù)
輸出描述:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-617843.html
c:9bit位寬的有符號(hào)數(shù)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-617843.html
代碼
`timescale 1ns/1ns
module data_select(
input clk,
input rst_n,
input signed[7:0]a,
input signed[7:0]b,
input [1:0]select,
output reg signed [8:0]c
);
//*************code***********//
/*代碼思路:case(select)來(lái)執(zhí)行不同的輸出
select = 0: 輸出a
select = 1: 輸出b
select = 2: 輸出a+b
select = 3: 輸出a-b*/
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
c <= 0;
else begin
case (select)
2'd0: begin
c <= a;
end
2'd1: begin
c <= b;
end
2'd2: begin
c <= a + b;
end
2'd3: begin
c <= a - b;
end
endcase
end
end
//*************code***********//
endmodule
到了這里,關(guān)于Verilog語(yǔ)法學(xué)習(xí)——LV6_多功能數(shù)據(jù)處理器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!