4位序列進製加法器 與 4位序列借位減法器

2021-08-25 14:57:10 字數 2014 閱讀 6746

4位序列進製加法器:

全加器的演算法為:

s = x ^ y ^ c_in ;

c_out = x*y + x*c_in + y*c_in ;

對應的verilog**為:

module adder_4bits(a, b, c_in, s_out, c_out);

input [3:0] a;

input [3:0] b;

input c_in;

output [3:0] s_out;

output c_out;

reg [3:0] s_out;

reg c_out;

reg [1:0] t1, t2, t3, t0;

task add;

input a, b, c_in;

output [1:0] t;

reg [1:0] t;

reg s_out, c_out;

begin

s_out = a ^ b ^ c_in;

c_out = (a&b) | (a&c_in) | (b&c_in);

t = ;

endendtask

always @(a or b or c_in) begin

add (a[0], b[0], c_in, t0);

add (a[1], b[1], t0[1], t1);

add (a[2], b[2], t1[1], t2);

add (a[3], b[3], t2[1], t3);

s_out = ;

c_out = t3[1];

endendmodule

得到的功能**圖為:

[img]

[color=darkred][size=medium]總結:任何n位加法器電路都可以用作減法器,方法是將減數取反,將進製輸入和進製輸出處理成具有相反有效電平的借位訊號。[/size][/color]

4位序列借位減法器的verilog**如下:

module subtractor_4bits(a, b, c_in, s_out, c_out);

input [3:0] a;

input [3:0] b;

input c_in;

output [3:0] s_out;

output c_out;

reg [3:0] s_out;

reg c_out;

reg [1:0] t1, t2, t3, t0;

task sub;

input a, b, c_in;

output [1:0] t;

reg b_n, c_in_n, c_out_n;

reg [1:0] t;

reg s_out, c_out;

begin

b_n = ~b;

c_in_n = ~c_in;

s_out = a ^ b_n ^ c_in_n;

c_out = (a&b_n) | (a&c_in_n) | (b_n&c_in_n);

c_out_n = ~c_out;

t = ;

endendtask

always @(a or b or c_in) begin

sub (a[0], b[0], c_in, t0);

sub (a[1], b[1], t0[1], t1);

sub (a[2], b[2], t1[1], t2);

sub (a[3], b[3], t2[1], t3);

s_out = ;

c_out = t3[1];

endendmodule

得到的功能**圖為:

[img]

[color=darkred][size=medium]注意:當被減數小於減數是,得到的波形結果是以補碼顯示為準,這時,應借助c_out值可算出真實的負數值。[/size][/color]

3 3 Verilog 4位超前進製加法器

使用工具 xilinx ise 14.7 用邏輯表示式實現4位的超前進製加法器,目的是為了減少輸出延遲,提高運算速度。在4位行波進製加法器中,計算過程中包含輸出訊號s i 與c i 作為中間變數,用他們作為下一級的輸入,並將多個1位全加器串聯起來造成了每一級的延遲累加,最終導致輸出延遲過大。為了減小...

4 序列式容器

template class vector 成員函式舉例 注意其中的記憶體管理 void vector insert iterator position,size type n,const t x else else ifdef stl use exceptions catch endif stl ...

Python基礎 4序列總結

區別 列表 list 元組 tuple 字典 dictionary 字串 char 修改可以修改 不可修改 可以修改 可以修改 索引有索引 有索引無索引 有索引型別 相同型別 不同型別 任何型別 文字字元 場景普遍使用 特定場景 描述事物 多種方法 切片可以切片 可以切片 不可切片 可以切片 名稱基...