日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDLBits答案(7)_Verilog多路选择器

發布時間:2023/12/19 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDLBits答案(7)_Verilog多路选择器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Verilog多路選擇器

HDLBits鏈接

定義

多路選擇器(Multiplexer)簡稱多路器,它是一個多輸入、單輸出的組合邏輯電路,在數字系統中有著廣泛的應用。它可以根據地址碼(選擇碼)的不同,從多個輸入數據流中選取一個,讓其輸出到公共的輸出端。


部分練習題

題目描述1:實現一個位寬為1的2-1的多路選擇器。當sel=0,選擇a,當sel=1,選擇b。

Solution1

module top_module( input a, b, sel,output out ); assign out = sel?b:a; endmodule

題目描述2:實現一個位寬為100的2-1的多路選擇器。當sel=0,選擇a,當sel=1,選擇b。

Solution2

module top_module( input [99:0] a, b,input sel,output [99:0] out );assign out = sel?b:a; endmodule

題目描述3:創建一個位寬為16的9-1的多路選擇器。sel=0選擇a, sel=1選擇b,以此類推。對于未使用的sel值(sel=9~15),將所有輸出位設置為1。

Solution3

module top_module( input [15:0] a, b, c, d, e, f, g, h, i,input [3:0] sel,output [15:0] out );always @(*) begincase(sel)4'd0: out = a;4'd1: out = b;4'd2: out = c;4'd3: out = d;4'd4: out = e;4'd5: out = f;4'd6: out = g;4'd7: out = h;4'd8: out = i;default:out = 16'hffff;endcaseendendmodule

題目描述4:創建一個位寬為1的256-1的多路選擇器。256個輸入都被打包成一個256位的輸入向量。sel=0表示選擇in[0],sel=1表示選擇in[1],以此類推。

Solution4

module top_module( input [255:0] in,input [7:0] sel,output out );assign out = in[sel]; endmodule

題目描述5:創建一個位寬為4的256-1的多路選擇器。256個4位輸入都被打包成一個1024位的輸入向量。sel=0選擇in[3:0],sel=1選擇in[7:4],sel=2選擇in[11:8],以此類推。

Solution5

module top_module( input [1023:0] in,input [7:0] sel,output [3:0] out );assign out = {in[sel*4+3],in[sel*4+2],in[sel*4+1],in[sel*4]}; endmodule

[David說]:題5中不能使用assign out = in[sel*4+3:sel*4],此時會報錯,因為該等式不能證明選擇的這個位寬是個常數。所以我們繼續按bit進行選取然后進行拼接。


總結

  • 學習了多路選擇器的相關知識。
  • 學習了可以根據向量索引進行數據的選擇,要注意的是被選取數據的位寬是否為常數。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的HDLBits答案(7)_Verilog多路选择器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。