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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDLBits(7)——Multiplexer Arithmetic Circuits

發(fā)布時(shí)間:2024/3/24 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDLBits(7)——Multiplexer Arithmetic Circuits 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

HDLBits(7)——Multiplexer & Arithmetic Circuits

    • ----- 61. 2-to-1 multiplexer -----
      • Problem Statement
      • Answer
    • ----- 62. 2-to-1 bus multiplexer -----
      • Problem Statement
      • Answer1
    • ----- 63. 9-to-1 multiplexer -----
      • Problem Statement
      • Answer
    • ----- 64. 256-to-1 multiplexer -----
      • Problem Statement
      • Answer
    • ----- 65. 256-to-1 4-bit multiplexer -----
      • Problem Statement
      • Answer
      • Note: An unfamiliar syntax
    • ----- 66. Half adder -----
      • Problem Statement
      • Answer1
      • Answer2
    • ----- 67. Full adder -----
      • Problem Statement
      • Answer1
      • Answer2
    • ----- 68. 3-bit binary adder -----
      • Problem Statement
      • Answer
    • ----- 69. Adder -----
      • Problem Statement
      • Answer
    • ----- 70. Signed addition overflow -----
      • Problem Statement
      • Answer1
      • Answer2
    • ----- 71. 100-bit binary adder -----
      • Problem Statement
      • Answer1
      • Answer2
    • ----- 72. 4-digit BCD adder -----
      • Problem Statement
      • Answer
      • Warning

----- 61. 2-to-1 multiplexer -----

Problem Statement

Create a one-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.

Expected solution length: Around 1 line.

Answer

module top_module( input a, b, sel,output out ); assign out = (~sel & a) | (sel & b);//other way: assign out = sel ? b : a;endmodule

----- 62. 2-to-1 bus multiplexer -----

Problem Statement

Create a 100-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.

Expected solution length: Around 1 line.

Answer1

module top_module( input [99:0] a, b,input sel,output [99:0] out );assign out = ( ~{100{sel}} & a) | ( {100{sel}} & b);//other way: assign out = sel ? b : a;endmodule

----- 63. 9-to-1 multiplexer -----

Problem Statement

Create a 16-bit wide, 9-to-1 multiplexer. sel=0 chooses a, sel=1 chooses b, etc. For the unused cases (sel=9 to 15), set all output bits to ‘1’.

Expected solution length: Around 15 lines.

Answer

module top_module( input [15:0] a, b, c, d, e, f, g, h, i,input [3:0] sel,output reg [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{1'b1}};endcaseendendmodule

----- 64. 256-to-1 multiplexer -----

Problem Statement

Create a 1-bit wide, 256-to-1 multiplexer. The 256 inputs are all packed into a single 256-bit input vector. sel=0 should select in[0], sel=1 selects bits in[1], sel=2 selects bits in[2], etc.

Expected solution length: Around 1 line.

Answer

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

----- 65. 256-to-1 4-bit multiplexer -----

Problem Statement

Create a 4-bit wide, 256-to-1 multiplexer. The 256 4-bit inputs are all packed into a single 1024-bit input vector. sel=0 should select bits in[3:0], sel=1 selects bits in[7:4], sel=2 selects bits in[11:8], etc.

Expected solution length: Around 1–5 lines.

Answer

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

Note: An unfamiliar syntax

Alternatively, “indexed vector part select” works better, but has an unfamiliar syntax:

  • assign out = in[sel*4 +: 4]; // Select starting at index “sel*4”, then select a total width of 4 bits with increasing ( +: ) index number.
  • assign out = in[sel*4+3 -: 4]; // Select starting at index “sel*4+3”, then select a total width of 4 bits with decreasing ( -: ) index number.
  • Note: The width (4 in this case) must be constant. So assign out = in[4*sel+3 : 4*sel] is the wrong way.

----- 66. Half adder -----

Problem Statement

Create a half adder. A half adder adds two bits (with no carry-in) and produces a sum and carry-out.

Expected solution length: Around 2 lines.

Answer1

module top_module( input a, b,output cout, sum );assign sum = a ^ b;assign cout = a & b;endmodule

Answer2

module top_module( input a, b,output cout, sum );assign {cout, sum} = a + b;endmodule

----- 67. Full adder -----

Problem Statement

Create a full adder. A full adder adds three bits (including carry-in) and produces a sum and carry-out.

Expected solution length: Around 2 lines.

Answer1

module top_module( input a, b, cin,output cout, sum );wire s, co1, co2;assign s = a ^ b;assign co1 = a & b;assign sum = cin ^ s;assign co2 = cin & s;assign cout = co1 | co2;endmodule

Answer2

module top_module( input a, b, cin,output cout, sum );assign {cout, sum} = a + b + cin;endmodule

----- 68. 3-bit binary adder -----

Problem Statement

Now that you know how to build a full adder, make 3 instances of it to create a 3-bit binary ripple-carry adder. The adder adds two 3-bit numbers and a carry-in to produce a 3-bit sum and carry out. To encourage you to actually instantiate full adders, also output the carry-out from each full adder in the ripple-carry adder. cout[2] is the final carry-out from the last full adder, and is the carry-out you usually see.

Answer

module top_module( input [2:0] a, b,input cin,output [2:0] cout,output [2:0] sum );adder adder1(.a(a[0]), .b(b[0]), .cin(cin), .cout(cout[0]), .sum(sum[0])); // low-bitadder adder2(.a(a[1]), .b(b[1]), .cin(cout[0]), .cout(cout[1]), .sum(sum[1]));adder adder3(.a(a[2]), .b(b[2]), .cin(cout[1]), .cout(cout[2]), .sum(sum[2])); // high-bitendmodulemodule adder( input a, b, cin,output cout, sum );assign {cout, sum} = a + b + cin;endmodule

----- 69. Adder -----

Problem Statement

Implement the following circuit:

(“FA” is a full adder)

Answer

module top_module (input [3:0] x,input [3:0] y, output [4:0] sum);wire [2:0] io;adder adder1(.a(x[0]), .b(y[0]), .cin(0), .cout(io[0]), .sum(sum[0])); // low-bitadder adder2(.a(x[1]), .b(y[1]), .cin(io[0]), .cout(io[1]), .sum(sum[1]));adder adder3(.a(x[2]), .b(y[2]), .cin(io[1]), .cout(io[2]), .sum(sum[2]));adder adder4(.a(x[3]), .b(y[3]), .cin(io[2]), .cout(sum[4]), .sum(sum[3])); // high-bitendmodulemodule adder( input a, b, cin,output cout, sum );assign {cout, sum} = a + b + cin;endmodule

----- 70. Signed addition overflow -----

Problem Statement

Assume that you have two 8-bit 2’s complement numbers(二補(bǔ)碼,一個(gè)更為熟悉的翻譯是二進(jìn)制補(bǔ)碼), a[7:0] and b[7:0]. These numbers are added to produce s[7:0]. Also compute whether a (signed) overflow has occurred.

Answer1

檢測(cè)補(bǔ)碼加法中的溢出(深入理解計(jì)算機(jī)系統(tǒng),CS:APP,P65):令s = x + y,當(dāng) x > 0, y > 0, s < 0 時(shí),s發(fā)生正溢出(即 x 和 y的最高位為 0,s 最高位為 1 時(shí)發(fā)生正溢出);當(dāng) x < 0, y < 0, s > 0 時(shí),s發(fā)生負(fù)溢出(即 x 和 y的最高位為 1,s 最高位為 0 時(shí)發(fā)生負(fù)溢出)。

module top_module (input [7:0] a,input [7:0] b,output [7:0] s,output overflow ); wire [7:0] io;adder adder0(.a(a[0]), .b(b[0]), .cin(0), .cout(io[0]), .sum(s[0])); // low-bitadder adder1(.a(a[1]), .b(b[1]), .cin(io[0]), .cout(io[1]), .sum(s[1]));adder adder2(.a(a[2]), .b(b[2]), .cin(io[1]), .cout(io[2]), .sum(s[2]));adder adder3(.a(a[3]), .b(b[3]), .cin(io[2]), .cout(io[3]), .sum(s[3])); adder adder4(.a(a[4]), .b(b[4]), .cin(io[3]), .cout(io[4]), .sum(s[4]));adder adder5(.a(a[5]), .b(b[5]), .cin(io[4]), .cout(io[5]), .sum(s[5]));adder adder6(.a(a[6]), .b(b[6]), .cin(io[5]), .cout(io[6]), .sum(s[6]));adder adder7(.a(a[7]), .b(b[7]), .cin(io[6]), .cout(io[7]), .sum(s[7])); // high-bitassign overflow = (a[7] & b[7] & ~s[7]) | (~a[7] & ~b[7] & s[7]); // 檢測(cè)補(bǔ)碼加法中的溢出(CS:APP,P65)endmodulemodule adder( input a, b, cin,output cout, sum );assign {cout, sum} = a + b + cin;endmodule

Answer2

module top_module (input [7:0] a,input [7:0] b,output [7:0] s,output overflow ); assign s = a + b;assign overflow = (a[7] & b[7] & ~s[7]) | (~a[7] & ~b[7] & s[7]);endmodule

----- 71. 100-bit binary adder -----

Problem Statement

Create a 100-bit binary adder. The adder adds two 100-bit numbers and a carry-in to produce a 100-bit sum and carry out.

Expected solution length: Around 1 line.

Answer1

module top_module( input [99:0] a, b,input cin,output cout,output [99:0] sum );genvar i;wire [99:0] io;generatefor(i = 0; i <= 99; i = i + 1)begin: add100if(i == 0)assign {io[i], sum[i]} = a[i] + b[i] + cin;elseassign {io[i], sum[i]} = a[i] + b[i] + io[i-1];endassign cout = io[99];endgenerateendmodule

Answer2

module top_module (input [99:0] a,input [99:0] b,input cin,output cout,output [99:0] sum );// The concatenation {cout, sum} is a 101-bit vector.assign {cout, sum} = a+b+cin;endmodule

----- 72. 4-digit BCD adder -----

Problem Statement

You are provided with a BCD (binary-coded decimal) one-digit adder named bcd_fadd that adds two BCD digits and carry-in, and produces a sum and carry-out.

module bcd_fadd (input [3:0] a,input [3:0] b,input cin,output cout,output [3:0] sum );

Instantiate 4 copies of bcd_fadd to create a 4-digit BCD ripple-carry adder. Your adder should add two 4-digit BCD numbers (packed into 16-bit vectors) and a carry-in to produce a 4-digit sum and carry out.

Answer

module bcd_fadd (input [3:0] a,input [3:0] b,input cin,output cout,output [3:0] sum );//...endmodulemodule top_module( input [15:0] a, b,input cin,output cout,output [15:0] sum );wire io0, io1, io2, io3;bcd_fadd bcd_fadd0(.a(a[3:0]), .b(b[3:0]), .cin(cin), .cout(io0), .sum(sum[3:0]));bcd_fadd bcd_fadd1(.a(a[7:4]), .b(b[7:4]), .cin(io0), .cout(io1), .sum(sum[7:4]));bcd_fadd bcd_fadd2(.a(a[11:8]), .b(b[11:8]), .cin(io1), .cout(io2), .sum(sum[11:8]));bcd_fadd bcd_fadd3(.a(a[15:12]), .b(b[15:12]), .cin(io2), .cout(io3), .sum(sum[15:12]));assign cout = io3;endmodule

Warning

  • Warning (10230): Verilog HDL assignment warning at tb_modules.sv(8): truncated value with size 32 to match size of target (4) File

Truncating values occur when the right side of an assignment is wider than the left side and the upper bits are cut off. This can indicate a bug if there is a truncation you didn’t expect, so check these carefully. The most common case where this isn’t a bug is when you’re using literals without a width (32 bits is implied), e.g., using assign a[1:0] = 1; instead of assign a[1:0] = 2’d1;.

總結(jié)

以上是生活随笔為你收集整理的HDLBits(7)——Multiplexer Arithmetic Circuits的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 谁有免费的黄色网址 | 成人av高清 | 轮番上阵免费观看在线电影 | 国产喷水在线 | 中文av免费| 国产区亚洲区 | caoporn免费在线 | 中文字幕美女 | 丰满少妇麻豆av苏语棠 | 成人免费看高清电影在线观看 | 男人与雌宠物交h | 亚洲成人诱惑 | av最新地址 | 中文字幕精品一区久久久久 | 欧美日韩免费看 | 日本国产精品 | 狠狠操综合网 | 亚洲精品在线中文字幕 | 黄色一级大片在线免费看产 | av在线专区| 国产精品自拍合集 | 色网在线观看 | 毛片网站视频 | 超碰男人的天堂 | 国产伦精品一区二区三区四区视频 | 久久久久久免费观看 | 国产精品视频www | va在线 | 黄色av免费在线播放 | 日韩不卡一二三区 | √8天堂资源地址中文在线 欧美精品在线一区二区 | 国产精品精品国产色婷婷 | 天天天天射 | 韩日视频在线观看 | 深爱激情av | 日日骚av一区二区 | 欧美在线中文 | 久久a久久| 伊人一区二区三区 | 久久伊人网站 | 性色av一区二区三区 | 中国在线观看免费视频 | 欧美性极品 | 精品无码久久久久成人漫画 | 亚洲av无码一区二区三区在线播放 | 男女免费观看视频 | 91精品在线视频观看 | 网友自拍咪咪爱 | 精品电影一区二区 | 中文字幕人妻伦伦 | 久久精品国产亚洲AV无码麻豆 | 黄色成人免费网站 | 国产三级一区二区三区 | 日韩精品中文在线 | 91精品婷婷国产综合久久竹菊 | 午夜激情福利在线 | 成人另类小说 | 四虎国产精品永久免费观看视频 | 亚洲一二三在线 | 青草久久久久 | 日本欧美国产一区二区三区 | av高清一区 | 精品国产一区二区三区日日嗨 | 性xxxx欧美| 蜜芽在线视频 | 日韩精品电影一区二区 | 在线视频这里只有精品 | 秋霞国产午夜精品免费视频 | 亚洲精品污一区二区三区 | 国产免费一区二区三区四区五区 | 亚洲精品中文字幕成人片 | 日韩精品视频观看 | 成人在线午夜 | 一区二区三区资源 | 少妇一级淫片免费放 | 国产三级在线 | 国产区在线视频 | 欧美一二 | 美国美女群体交乱 | 99在线播放视频 | 国产福利91精品一区二区三区 | 在线免费观看毛片 | 97精品久久 | 激情网站视频 | 成年人免费av | 亚洲天堂8| 91精品网 | zzjj国产精品一区二区 | av天堂一区二区 | 九色视频在线播放 | 综合网视频 | 久久久一二三区 | 大香蕉毛片 | 日韩电影一区二区 | 无码少妇精品一区二区免费动态 | 草草视频在线免费观看 | 欧美粗又大| 久久久av网站 | 国产剧情一区二区三区 |