三种16位加法器(串行、并行、超前进位)adder 下载本文

内容发布更新时间 : 2024/11/14 5:04:01星期一 下面是文章的全部内容请认真阅读。

//进位链加法器

modulecarry_chain_adder(x, y, cin, sum, cout); parameterN = 16; //N-bits input cin; input [N-1:0] x, y; output [N-1:0] sum; output cout; reg cout, q[N:0], p[N-1:0], g[N-1:0]; reg [N-1:0] sum; always @(x or y or cin)begin //:ADDER integeri; q[0] = cin; for(i=0; i

// (并行)二进制行波进位加法器

module ripple_carry_adder(x, y, cin, sum, cout); parameterN = 16; input cin; input [N-1:0] x, y; output [N-1:0] sum; output cout; reg cout; reg [N-1:0] sum; reg q[N:0]; always @(x or y or cin)begin //:ADDER integeri; q[0] = cin; for(i=0; i<=N-1; i=i+1)begin q[i+1] = (x[i]&y[i]) | (x[i]&q[i]) | (y[i]&q[i]); sum[i] = x[i] ^ y[i] ^ q[i]; end cout = q[N]; end endmodule

// 二进制跳跃进位加法器(超级进位)

modulecarry_skip_adder(x_in, y_in, c_in, sum, c_out); parameterN = 16; parameterS = 4; input c_in; input [N-1:0] x_in, y_in; output [N-1:0] sum; reg [N-1:0] sum; output c_out;

reg c_out; integeri, j; reg [N:0] q; always @(x_in or y_in or c_in)begin q[0] = c_in; begin carry_skip_add_cell(x_in[S-1:0], y_in[S-1:0], q[0], q[S:1]); for(j=0; j<=S-1; j=j+1) sum[j] = x_in[j] ^ y_in[j] ^ q[j]; carry_skip_add_cell(x_in[2*S-1:S], y_in[2*S-1:S], q[S], q[2*S:S+1]); for(j=0; j<=S-1; j=j+1) sum[S+j] = x_in[S+j] ^ y_in[S+j] ^ q[S+j]; carry_skip_add_cell(x_in[3*S-1:2*S], y_in[3*S-1:2*S], q[2*S], q[3*S:2*S+1]); for(j=0; j<=S-1; j=j+1) sum[2*S+j] = x_in[2*S+j] ^ y_in[2*S+j] ^ q[2*S+j]; end c_out = q[N]; end // S比特分组进位链 taskcarry_skip_add_cell; input [S-1:0] x, y; inputcin; output [S:1] cout; reg q[S:0], p[S-1:0], g[S-1:0], accumulator, generalized_p; integeri; begin q[0] = cin; for(i=0; i<=S-1; i=i+1)begin p[i] = x[i]^y[i]; g[i] = y[i]; q[i+1] = (p[i])?q[i]:g[i]; end accumulator = p[0]; for(i=1; i<=S-1; i=i+1) accumulator = accumulator & p[i]; generalized_p = accumulator; cout[S] = (generalized_p) ? c_in : q[S]; for(i=1; i<=S-1; i=i+1) cout[i] = q[i]; end endtask endmodule