LV7_求兩個(gè)數(shù)的差值
題目來源于??途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)a,b的大小關(guān)系,求解兩個(gè)數(shù)的差值:輸入信號(hào)a,b為8bit位寬的無(wú)符號(hào)數(shù)。如果a>b,則輸出a-b,如果a≤b,則輸出b-a。
接口信號(hào)圖如下:
輸入描述:
clk:系統(tǒng)時(shí)鐘
rst_n:復(fù)位信號(hào),低電平有效
a,b:8bit位寬的無(wú)符號(hào)數(shù)
輸出描述:文章來源:http://www.zghlxwxcb.cn/news/detail-615787.html
c:8bit位寬的無(wú)符號(hào)數(shù)文章來源地址http://www.zghlxwxcb.cn/news/detail-615787.html
代碼
`timescale 1ns/1ns
module data_minus(
input clk,
input rst_n,
input [7:0]a,
input [7:0]b,
output reg [8:0]c
);
//*************code***********//
/*代碼思路: if(a>b),輸出a-b
if(a<=b),輸出b-a
簡(jiǎn)單的if判斷
*/
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
c <= 0;
else begin
if(a>b)
c <= a-b;
else if(a<=b)
c <= b-a;
end
end
//*************code***********//
endmodule
到了這里,關(guān)于Verilog語(yǔ)法學(xué)習(xí)——LV7_求兩個(gè)數(shù)的差值的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!