功能特性

32位加減法器設計

設計思路

基於一位全加器,設計32位並行加法器。並行加法器中全加器的位數與運算元相同,影響速度(延時)的主要因素是進位訊號的傳遞。主要的高速加法器【1】有基本上都是在超前進位加法器(CLA)的基礎上進行改進或混合進位。而在結構方面,行波進位加法器是最簡單的整數加法器。其基本原理如下圖所示:

32位加減法器設計

透過在模組輸入埠新增運算子(表示加法或減法),符號標識(表示有符號或無符號操作),可以實現有符號、無符號定點數的加減法及求補運算。

Verilog編碼

一位全加器門級描述

module

full_add

sum

a

b

cin

cout

);

output

sum

cout

input

a

b

cin

// ————- wire declaration ——

// iner wire for count

wire

c1

c2

c3

// iner wire for sum

wire

s1

s2

s3

s4

// logical combination for cout

and

C1

c1

a

b

);

and

C2

c2

b

cin

);

and

C3

c3

cin

a

);

// logical combination for sum

and

S1

s1

a

~

b

~

cin

);

and

S2

s2

~

a

b

~

cin

);

and

S3

s3

~

a

~

b

cin

);

and

S4

s4

a

b

cin

);

// output assignment

or

C0

cout

c1

c2

c3

);

or

S0

sum

s1

s2

s3

s4

);

endmodule

32位加減法器:

module

add32

sum

a

b

sub

sign

overflow

);

/* arg description:

sub : 1 for substraction; 0 for add

sign : 1 for signed; 0 for unsigned

*/

input

31

0

a

b

input

wire

sub

sign

output

31

0

sum

output

wire

overflow

// ———— iner wire declaration ————

wire

31

0

c

// assignmet for output value

assign

overflow

=

sign

c

31

^

c

30

])

sub

^

c

31

]);

// ———— module instantiation ————

full_add

add0

sum

sum

0

]),

a

a

0

]),

b

sub

^

b

0

]),

cin

sub

),

cout

c

0

])

);

……

endmodule

RTL模擬

32位加減法器設計

無(有)符號加(減)法

32位加減法器設計

求補運算

測試程式碼

`timescale

1

ns

/

1

ns

module

test

reg

31

0

a

b

reg

sub

sign

wire

overflow

wire

31

0

sum

// assubment for input value

initial

begin

a

=

0

b

=

0

forever

begin

#

20

a

=

0

//a = a + 32‘d10000;

b

=

b

+

32

’d20000

#

20

end

end

initial

begin

sub

=

0

forever

begin

#

30

sub

=

~

sub

#

20

end

end

initial

begin

sign

=

0

forever

begin

#

50

sign

=

~

sign

#

50

end

end

// module instantiation

add32

u_add32

sum

sum

),

a

a

),

b

b

),

sub

sub

),

sign

sign

),

overflow

overflow

);

綜合報告

綜合工藝:SMIC180nm

綜合工具:Design Compiler

32位加減法器設計

32位加減法器原理圖

32位加減法器設計

一位全加器原理圖

面積報告

32位加減法器設計

時延報告

32位加減法器設計

功耗報告

32位加減法器設計

參考資料