Take Home Exam Solutions
Take Home Exam Solutions
Take Home Exam Solutions
April 2021
Contents
1 Solution of Problem 1 2
2 Solution of Problem 2 4
3 Solution of Problem 3 8
4 Solution of Problem 4 16
5 Solution of Problem 5 17
5.1 POINT A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6 Solution of Problem 6 19
6.1 POINT A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.2 POINT B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.3 POINT C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.4 POINT D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7 Solution Problem 7 23
8 Solution of Problem 8 33
9 Solution of Problem 9 34
10 Appendix 34
10.1 Commonly used sub-circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
10.2 Step by Step computation of the non restoring square root: Python
Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
10.3 Modulo 9 adder & multiplier : test of correctness . . . . . . . . . . . . . 40
1
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
1 Solution of Problem 1
r=5, α= 3 , β=4
α β
λ≥ , µ≥
r−1 r−1
λ=µ=1 =⇒ ti+1 ∈ {−1; 0; 1}
To compute the range of the comparison constants, the formula given in “Gen-
eralized Signed-Digit Number Systems” by B. Paharmi is used:
kr − (α − λ) ≤ Ck ≤ (k − 1)r + β − µ + 1
C1min = 5 − (3 − 1) = 3
=⇒ 3 ≤ C1 ≤ 4
C1max = 4 − 1 + 1 = 4
C0min = 3 − 4 = −1
=⇒ −2 ≤ C0 ≤ −1
C0max = −5 + 4 − 1 + 1 = −1
Finally, the comparison constants are within the following ranges:
C−1 = ∞ ; C0 = −1 ; 3 ≤ C1 ≤ 4 ; C2 = +∞
ti+1 = 1 , if pi ≥ C1
ti+1 = −1 , if pi < C0
In the following, the logic equations which define the transfer ti+1 are reported.
Let pi be expressed as:
a b c d e
pi = ↑ ↑ (5 bit 2′ s complement)
MSB LSB
Point A
For the generate signals g1 , g−1 , the logic equations are:
g1 = ā(b ∨ c)
2
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
Point B
The quantity si is computed as the sum of two 4 bits number and a 5 bit number
(pi ).
si = wi + ti = pi − 5ti+1 + ti (1)
Any 5 bit number can be expressed in the form:
The addition in equation (1) can be computed as the sum of only 4 bits numbers.
The dot reduction tree is depicted in Figure 1 (Dadda’s approach used).
pi
- 5 ti+1
4 HA ti
3 FA + 1 HA
3 FA + 1 HA
4 bits CPA
Adder
3
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
2 Solution of Problem 2
[a]
The system has the following dynamic range:
Smallest possible number : -16 x 15
2
x 13
= −1560
Largest possible numberr: 1559
The efficiency ϵ of the system is
RNS ( 16 | 15 | 13 )
4Bit 4Bit 4Bit
16 × 15 × 13
ε= ≈ 76.19%
212 − 1
[b]
[c]
RNS ( 16 | 15 | 13 )
x 12 0 8
y 13 10 4
(x+y) 9 10 12
(x-y) 15 5 4
(x.y) 12 0 6
4
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
[d]
The structure of the described adder is the following:
MOD 16 MOD 15 MOD 13 MOD 16 MOD 15 MOD 13
4
4 4 4 4
4 4 4
4 4 4
Inside the MOD16, MOD15 and MOD13 we have a 4 bit adder with the follow-
ing structure:
A3 B3 A2 B2 A1 B1 A0 B0
FA FA FA FA
Not
used
C3 C2 C1 C0
The RNS adder and a ripple carry adder (same dynamic range) will be now
compared.
AREA COMPARISON ( in terms of FA & HA):
F.A. N° H.A. N°
RNS 9 3
R.C. 12 0
5
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
DELAY COMPARISON
A 11 B 11 A 10 B 10 A9 B9 A8 B8 A7 B7 A6 B6 A0 B0
FA FA FA FA FA FA FA C in
C out
S 11 S 10 S9 S8 S7 S6 S0
: critical path
FA FA FA FA
The RNS adder has a shorter critical path, thus is more effective than the ripple
carry adder.
[d]
To solve the inequality, the numbers are converted to base 10.
(1|0|0) =2145
RNS(16|15|13)
(0|1|0) =1456
RNS(16|15|13)
(0|0|1) =2640
RNS(16|15|13)
6
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
(3|4|5) =499
RNS(16|15|13)
(4|0|2) =992
RNS(16|15|13)
7
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
3 Solution of Problem 3
According to the IEEE single precision floating point standard, 23 bits are ded-
icated to store the significant. This means that a significant adder has the
following number of bits:
OR 1
AND 1
XOR 2
NOT 1
2:1 MUX (MUXBIT ) 4
2:1 bus MUX (MUXBUS: n lines ) 4× bus lines
4 bitt carry network 29
4 bit carry-look ahead 49
Full Adder 7
For the evaluation of the delay, same assumptions as in the textbook are herein
adopted.
8
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
A B
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
3..0 3..0 3..0 3..0 3..0 3..0 3..0 3..0 3..0 3..0 3..0 3..0
B A B A B A B A B A B A CIN
4 BIT LA ADDER C0 4 BIT LA ADDER C0 4 BIT LA ADDER C0 4 BIT LA ADDER C0 4 BIT LA ADDER C0 4 BIT LA ADDER C0
G P G P G P G P G P G P
0 0 S 0 0 S 0 0 S 0 0 S 0 0 S 0 0 S
3 3 3..0 3 3 3..0 3 3 3..0 3 3 3..0 3 3 3..0 3 3 3..0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00..24
G P C G P C G P C G P
3 3 3 2 2 2 1 1 1 0 0
G P
Carry Generator C0
0 0
3 3
G P C G P C G P C G P
3 3 3 2 2 2 1 1 1 0 0
C0
G
0
P
0
Carry Generator
3 3
24
25 Bit Output
cout
4 BIT LA ADDER = 4 bits Carry-Lookahead Adder
For the analysis of the circuit we deduce that the area CCLA and TCLA delay of
the circuit can be expressed as:
9
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
24 13 12 0
12 bit adder 0 cin
13 bit adder
12 bit adder 1
13 13 13
c13
cout
12
The 12 and 13 bit adders have been implemented with carry-lookahead tech-
nique. In particular, a 4 bit carry-lookahead adder and a 4 bit carry propagate
network have been used as building blocks. A more detailed schematics for the
25 bits single-level carry select adder is depicted in Figure 4.
10
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 3 2 1 0 3 2 1 0 3 2 1 0
3 2 1 0 3 2 1 0 3 2 1 0
1 1 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 0 1 0 9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0
00..11
'0'
G P C G P C G P C G P G P C G P C G P C G P
3 3 3 2 2 2 1 1 1 0 0 3 3 3 2 2 2 1 1 1 0 0
Carry Generator Carry Generator
C0 C0
G P G P
0 0 0 0
3 3 3 3
1
2
2 2 2 2 2 1 1 1 1 1 1 1
4 3 2 1 0 9 8 7 6 5 4 3
2 2 2 2 2 1 1 1 1 1 1 1
4 3 2 1 0 9 8 7 6 5 4 3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
0 0 0 0
3 2 1 0
0 0 0 0
3 2 1 0
0 0 0 0
3 2 1 0 25 bits output
1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0
00..11
'0'
G P C G P C G P C G P
3 3 3 2 2 2 1 1 1 0 0
Carry Generator
C0
G P 2
0 0 5
3 3
1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0 1 0 9 8 7 6 5 4 3 2 1 0
12 bits Carry-Lookahead
1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0
1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0 Adder
15..00 15..00
I1 I0 I1 I0 2 2 2 2 2 1 1 1 1 1 1 1
S0 16 Mux 2-1 4 3 2 1 0 9 8 7 6 5 4 3
S0 Mux 2-1 Q
15..00
Q (Id1993)
1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0
11
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
24 19 18 13 12 7 6 0
cin
6 Bits Adder 6 Bits Adder 6 Bits Adder 7 Bits Adder
7 7
6 6 7 7 7
c7
6
c13
13
12
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
0 0 0 0 0 0 0 0
3..0 3..0 3..0 3..0 3..0 3..0 3 2 1 0 3 2 1 0
BA BA BA BA BA BA
B A B A B A
LA CIN LA CIN 4 BIT LA ADDER C0 '0' LA CIN LA CIN 4 BIT LA ADDER C0 '0' LA CIN LA CIN 4 BIT LA ADDER C0 '0' 3..0 3..0
BA BA BA
B A
G P G P G P
0 0 S 0 0 S 0 0 S LA CIN LA CIN LA CIN 4 BIT LA ADDER C0
G P S G P S 3 3 3..0 G P S G P S 3 3 3..0 G P S G P S 3 3 3..0
G P
0 0 S
G P S G P S G P S 3 3 3..0
0 0 0 0 0 0 0 0 0 0 0 0
5 4 3 2 1 0 5 4 3 2 1 0 0 0
5 4
0 0 0 0 0 0 0 0
3 2 1 0 0 0 0 3 2 1 0
'0' 6 5 4
0 0 0 0
'0' 0 0 0 0 3 2 1 0 '0' 0 0 0 0
3 2 1 0 3 2 1 0
0 0 0 0
3 2 1 0
G P C G P C G P C G P G P C G P C G P C G P G P C G P C G P C G P
3 3 3 2 2 2 1 1 1 0 0 3 3 3 2 2 2 1 1 1 0 0 3 3 3 2 2 2 1 1 1 0 0
Carry Generator Carry Generator Carry Generator G P C G P C G P C G P
C0 C0 C0 3 3 3 2 2 2 1 1 1 0 0
G P G P G P
0 0 0 0 0 0 Carry Generator
3 3 3 3 3 3 C0
G P
0 0
3 3
6 bits Carry-Lookahead Adder 6 bits Carry-Lookahead Adder 6 bits Carry-Lookahead Adder
2
4
2
3
2 2 2 1
2 1 0 9
1
8
1
7
1 1 1 1
6 5 4 3
1
2
1
1
1 0 0 0
0 9 8 7
cin
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0
6 bits Carry-
Lookahead Adder
0 0 3 2 1 0 0 0 3 2 1 0 0 0 3 2 1 0
5 4 5 4 5 4
00..05
0 0 0 0
3 2 1 0
'0' '0'
0 0 0 0 0 0 0 0 '0'
3 2 1 0 3 2 1 0
G P C G P C G P C G P G P C G P C G P C G P G P C G P C G P C G P
3 3 3 2 2 2 1 1 1 0 0 3 3 3 2 2 2 1 1 1 0 0 3 3 3 2 2 2 1 1 1 0 0
Carry Generator '1' Carry Generator '1' Carry Generator '1'
C0 C0 C0
G P G P G P
0 0 0 0 0 0
3 3 3 3 3 3
I1 I0 05..00 05..00
I1 I0
S0 Mux 2-1 S0 6 Mux 2-1
Q
05..00 05..00 05..00 05..00 Q 07..00
I1 I0 I1 I0
S0 6 Mux 2-1 S0 6 Mux 2-1
Q Q
05..00 05..00
0
0 0 0 0 0 0 0 0 0 0 0 0 0
: 5 4 3 2 1 0 5 4 3 2 1 0
0
7
1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 9 8 7 6 5 4 3 2 1 0
5 4 3 2 1 0 5 4 3 2 1 0
I1 I0 I1 I0
S0 Mux 2-1 S0 Mux 2-1
1 1 0 0 0 0 0 0 0 0 0 0 0
Q Q 1 0 9 8 7 6 5 4 3 2 1 0 0
:
0
7
I1 I0 11..00 11..00
I1 I0
S0 Mux 2-1 S0 12 Mux 2-1
Q
Q 12..00
00..15
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0 5 4 3 2 1 0 6 5 4 3 2 1 0
cout 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
25 bits output
BA
B
LA CIN
A
G P S
G
CIN
P Computer Arithmetic - Academic Year 2020 - 2021
T.H.E. Problem No. 3
S
13
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
√
topt = 2 k = 10
b=1
1234554321
However, it should be observed that with this distribution the adder would have
30 bits. Thus, the total number of blocks is pruned to 9 and the block size
distribution is:
123454321
The schematic of a 25 bits Optimal variable-block carry skip adder is depicted
in Figure 7. The sub-adders have been implemented as ripple carry adders. Ex-
tra circuitry was added to generate the propagate signals in each block. Using
the same mathematical notation as in the textbook, the propagate signal de-
fined for each k bit ripple carry adder block is
p[0,k] = p0 p1 . . . pk (3)
Thus, the hardware necessary to compute the propagate signal is estimated
as in Table 2:
14
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
25 bit input
25 bit input 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
7 6 5 4 3 2 1 0 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
7 6 5 4 3 2 1 0 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 0 2 1 0 2 1 0 3 2 1 0 3 2 1 0 4 3 2 1 0 4 3 2 1 0 3 2 1 0 3 2 1 0 2 1 0 2 1 0 1 0 1 0
1..0 1..0 2..0 2..0 3..0 3..0 5..0 5..0 3..0 3..0 3..0 3..0 3..0 3..0
B A B A B A B A B A B A B A
A B
2 BITS ADDER CI 3 BITS ADDER CI 4 BITS ADDER CI 5 BITS ADDER CI 4 BITS ADDER CI 3 BITS ADDER CI 2 BITS ADDER CI
Co FA Ci P01 RIPPLE CARRY P02 RIPPLE CARRY P03 RIPPLE CARRY P04 RIPPLE CARRY P03 RIPPLE CARRY P02 RIPPLE CARRY P01 RIPPLE CARRY A B
S CO S CO S CO S CO S CO S CO S CO S Co FA Ci
1..0 2..0 3..0 4..0 3..0 2..0 1..0
S
S0
Cout Mux 2-1 S0 S0 S0 S0 Cin
Mux 2-1 Mux 2-1 Mux 2-1 S0 S0 S0 S0 Mux 2-1
I1 Mux 2-1 Mux 2-1 Mux 2-1 Mux 2-1
Q I1 I1 I1 I1
I0 Q Q Q I1 I1 I1 I1 Q
I0 I0 I0 Q Q Q Q I0
I0 I0 I0 I0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 2 1 0 3 2 1 0 4 3 2 1 0 3 2 1 0 2 1 0 1 0
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00..24
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
25 bit output
i BIT LA = i bits Carry-Lookahead Adder
Adder Selection
From our previous analysis, we conclude that the 25 bits Optimal variable-
block carry skip adder occupies the minimum area among the examined ar-
chitectures. Therefore, since our selection criteria is cost-effectiveness, this
architecture should be chosen for integration into the FFU.
15
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
4 Solution of Problem 4
24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
L1
Brent
Kung
L2
L3
K.Stone
L4
L5
L6
Brent
Kung
L7
s24 s23 s22 s21 s20 s19 s18 s17 s16 s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0
Let us assume:
• 1 AND / OR : 1 unit
• 1 XOR : 2 units
Delay = 2 + 7 × 2 + 2 = 18 units
16
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
5 Solution of Problem 5
5.1 POINT A
Since it is requested to minimize the delay, the Wallace approach is used. The
dot reduction diagram is shown in Figure 8.
2FA+1HA
2HA+1FA
1HA+1FA
2BIT CPA
(carry out
not used)
17
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
0
1
2
3
4
5
6
7
8
9
10
18
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
6 Solution of Problem 6
6.1 POINT A
3 bits integers 2’s complement range: [−4; 3]
y max = 2 · 3 · 3 + 20 + 3 · 3 = 27 + 20 = 47
(a = 3, b = 3 , c = 3 , d = −4)
y min = −2 · 4 · 3 − 3 · 4 − 5 · 3 = −51
(a = 3, b = −4 , c = −4 , d = 3)
or (a = −4, b = 3 , c = −4 , d = 3)
The range y min ; y max
consists of 99 values. Thus,
6.2 POINT B
It is convenient to express y as follows:
y = 2(ab) + 2c − 4d − d
For the ab multiplication, the modified Baugh-Wooley method is used. In the
following, the method of operand addition matrix is shown.
6 5 4 3 2 1 0 COL
a 2 b0 a 1 b0 a 0 b0
a 2 b1 a 1 b1 a 0 b1
2ab
a 2 b2 a 1 b2 a 0 b2
1 1
c2 c2 c2 c2 c1 c0 2c
c2 c2 c2 c2 c2 c1 c0 c
d2 d2 d2 d1 d0 -4d
1
d2 d2 d2 d2 d2 d1 d0 -d
1
19
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
6 5 4 3 2 1 0
d2 d2 c2 a 2 b0 a 1 b0 a 0 b0 c0
c2 a 2 b2 a 2 b1 a 1 b1 a 0 b1 c0 d0
1 c2 a 1 b2 a 0 b2 c1 c1 1
1 d1 c2 d1
d2 d0
d2
All the carries generated in column 6 are ignored because from POINT A the
operation result can be represented with 7 bits.
6.3 POINT C
Since it is required to minimize both delay and area, Dadda’s reduction tree is
applied (see Figure 9).
20
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
6 5 4 3 2 1 0
1
2
=> n(h)= 6
3
4
Since the result of the operation
can be expressed as a 7 bit number, 5
carries generated in this column
are not taken into account. 6
7
1 HA
3 FA + 1 HA 6
4
4 FA + 2 HA
1
n(h)= 3 => n(h)= 2
2
3
7 FA
21
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
d2 d1 d0 c2 c1 c0 b2 b1 b0 a2 a1 a0
partial products
K6 K5 K4 K3 K2 K1 K0
2..0 2..0 3..0 4..0 6..0 3..0 2..0
K6 K5 K0
K4 K2 K1
3 bits
3 bits
3 bits
7 bits
4 bits
K3
4 bits
5 bits
00
01
A B
Co HA
00
01
S
LEVEL 1
00
01
02
02
03
A B A B A B
Co FA Ci Co FA Ci Co FA Ci
02
S S 03 S
LEVEL 2
03
A B
Co HA
S
00 00
01 01
00
01
04
05
A B A B A B A B A B A B LEVEL 3
Co HA Co FA Ci Co FA Ci Co FA Ci Co FA Ci Co HA
S S S S S S
02
02
00
04 06 01
02
02
03
A B A B A B A B A B A B A B
Co FA Ci Co FA Ci Co FA Ci Co FA Ci Co FA Ci Co FA Ci Co FA Ci LEVEL 4
S S S S S S S
A(5) B(5) A(4) B(4) A(3) B(3) A(2) B(2) A(1) B(1) A(0) B(0)
y0
y6 y5 y4 y3 y2 y1
K6 K5 K4 K3 K2 K1 K0
ADDR 5 d[2]
ADDR 6 ‘1’
22
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
6.4 POINT D
BRENT KUNG PARALLEL PREFIX ADDER
5 4 3 2 1 0
S5 S4 S3 S2 S1 S0
3F A + 1HA + 1 CarryOperator
7 Solution Problem 7
Modulo 9 Adder design
A modulo 9 adder is implemented by means of a 4 bit carry propagate adder.
Its result is then corrected to be compliant with the modulo 9 arithmetic rules.
The schematic of the adder is depicted in Figure 11.
23
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
A B
00..03
0 0 0 0 0
0 3 2 1 0
:
0
3
0 0 0 0
3 2 1 0
A B A B A B A B
Co FA Ci Co FA Ci Co FA Ci Co HA
S S S S
0 0 0 0
3 2 1 0
00..03
Correction
circuit L2
3..0
IN
'0' '1'
L1
0 0 0 0 O
3 2 1 0 3..0
03..00 03..00
I1 I0
S0 4 Mux 2-1
Q
03..00
Correction
circuit L1
C
• L1 c = 0
The behavior of the L1 circuit is described by the following K-MAPs
24
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
O[3] S1 S0 O[2] S1 S0
00 01 11 10 00 01 11 10
00 0 0 0 0 00 0 0 0 0
S3 S2
S3 S2
01 0 0 0 0 01 1 1 1 1
11 0 0 0 0 11 0 1 1 1
10 1 0 0 0 10 0 0 0 0
O[1] S1 S0 O[0] S1 S0
00 01 11 10 00 01 11 10
00 0 0 1 1 00 0 1 1 0
S3 S2
S3 S2
01 0 0 1 1 01 0 1 1 0
11 1 0 1 0 11 1 0 0 1
10 0 0 1 0 10 0 0 0 1
25
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
IN
03..00
0 0 0 0
0 1 2 3
0 0 0 0
3 2 1 0
00..03
03..00
• L2 c = 1
This case is observed when both input are 10002 . Thus, L2 it is simply made
of a constant, namely 0111 (the result of the RNS addition).
26
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
Case 1 Case 2
0 0
0 1
A 0 0 0 0 0
0 0 0 0 0
D 0 B 0 0 0 0
0 0 0 0 0
C
Case 3 Case 4
1 0 0 0 1 0 0 0
1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
6 5 4 3 2 1 0
2 2 2 2 2 2 2
p p p p
30 20 10 00
p p p p
31 21 11 01
p p p p
32 22 12 02
p p p p
33 23 13 03
The above partial product matrix has been deduced by means of the follow-
27
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
ing equations:
m
X m
X
i i
R = |A × B|2m +1 = a2 bj 2 j
i=0 j=0 2m +1
m X
X m
= pij 2i+j
i=0 j=0 2m +1
1. |22m |2m +1 = 1
4 3 2 1 0
2 2 2 2 2
p v q p q v p v p33
20 2 10 2 00
p v q p p
11 01
21 0
p v q p p
22 1 12 02
s2i 2m +1
= −s|i|m 2m +1
= (2m + 1 − s) 2|i|m 2m +1
= s̄2 |i|m
+2 2 m |i|m
2m +1
, i ∈ [m; 2m − 2] (1)
According to equation (1), if a term in the ith position is inverted and rewritten
in position |i|m , the partial product matrix does not change when a correction
term ”2m 2|i|m ” is taken into account.
The partial product matrix is thus rewritten as:
28
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
2 1 0
2 2 2
p v q p q vp v p
20 2 10 2 00 33
p p p v q
11 01 21 0
p p v q p
02 22 1 12
Finally,
m−1
(7)
X
R = |A × B|2m +1 = ppi + 3
i=0 2m +1
29
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
B
A
0 0 0 0
3 2 1 0
p30
p20
p10
p00
p31
p21
p11
p01
p32
p22
p12
p02
p33
p23
p13
p03
'1' '1'
A B A B A B
Co HA Co FA Ci Co FA Ci
S S S
A B A B A B
Co FA Ci Co FA Ci Co FA Ci
S S S
A B A B A B
2 2 1 1 0 0
30
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
B3 A2 B1 A1 B0 A0
A B A B A B
Co FA Ci Co FA Ci Co HA
S S S
L1 circuit developed
for the mod 9 adder
0 0 0 0
3 2 1 0
00..03
0 0 0 0
0 1 2 3
0 0 0 0
3 2 1 0
00..03
03..00
A BI
03..00
0 0 0 0
0 1 2 3
O0 O1 O2 O3
31
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
• Generation of the all possible input patterns together with the expected
output result by means of a python script.
Both multiplier and adder have successfully passed the validation process.
The VHDL code and the python script for io generation are available at section
10.3.
2
https://www.digitalelectronicsdeeds.com
32
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
8 Solution of Problem 8
To solve this class of problem I have developed the Python script3 reported in
section 10.2. The output is listed below:
==========================================
z = 01.011010110 NONRESTORING Algorithm
1 Guard digit(s) automatically added
==========================================
s[0] = z-1 0000.011010110 q_0= 1 q[0]= 0001.000000000
2s[0] 0000.110101100 q_-1= 1 q[1]= 0001.100000000
1101.100000000
-----------------------------------------
s[1] 1110.010101100 q_-2= -1 0001.010000000
2s[1] 1100.101011000
0010.110000000
-----------------------------------------
s[2] 1111.011011000 q_-3= -1 0001.001000000
2s[2] 1110.110110000
0010.011000000
-----------------------------------------
s[3] 0001.001110000 q_-4= 1 0001.001100000
2s[3] 0010.011100000
1101.101100000
-----------------------------------------
s[4] 0000.001000000 q_-5= 1 0001.001110000
2s[4] 0000.010000000
1101.100110000
-----------------------------------------
s[5] 1101.110110000 q_-6= -1 0001.001101000
2s[5] 1011.101100000
0010.011011000
-----------------------------------------
s[6] 1110.000111000 q_-7= -1 0001.001100100
2s[6] 1100.001110000
0010.011001100
-----------------------------------------
s[7] 1110.100111100 q_-8= -1 0001.001100010
2s[7] 1101.001111000
0010.011000110
-----------------------------------------
s[8] 1111.100111110 Negative 0001.001100001
0010.011000011
-----------------------------------------
Final Result 0001.00110000
33
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
9 Solution of Problem 9
Point A
Point B
(a + b) + c = No Difference
a + (b + c) = a − (0.397226 × 108 ) = 0.34 × 104
Point C
10 Appendix
34
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
03
P3
03
03
03 00..03 : A
G3 00
03
P03 02
P2 03
02
00..03 :
00
B
02
G2
02
01
P1
G03 01
01
G1
01
00
P0
00
00
G0
00
C3
C0
C0
03 03
0 0 0 0
3 2 1 0
C2
02 02
03
S :
00
C1
01 01
0
0
:
0
3
00 00
P3
G3
P03
P2
G2
G03 P1
G1
P0
G0
C3 C0
C2
C1
35
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
41 # check overflow
42 if(a[0]== b[0]):
43 if( result [0]!= a[0]):
44 print (" Overflow ")
45 return None
46 else:
47 return result
48 else:
49 return result
50 else:
51 print ("a,b, must agree with alu bit len.")
52 return None
53
54
55 def twosCompl (self ,a):
56 not_a = ""
57 for d in a:
36
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
58 if(d=="1"):
59 not_a = not_a + "0"
60 else:
61 not_a = not_a + "1"
62 one = self.unit ()
63 return self.add(not_a ,one)
64
65
66 def sub(self ,a,b):
67 # a - b
68 minus_b = self. twosCompl (b)
69 return self.add(a, minus_b )
70
71 def shiftLeft (self ,a,shift):
72 if(len(a)== self.bits):
73 return a[1:]+"0"
74 else:
75 print ("a=",a , "must have a len of ", self.bits)
76
77 def isPos(self ,a):
78 #check if a>0
79 if(a[0]== '1'):
80 return False
81 else:
82 return True
83
84
85 class binSQRT :
86 def __init__ (self , binValue ):
87 self.val = binValue
88
89 def trial2Subtract (self , prev_q , q_signed_digit , j , the_alu ):
90 temp1 = the_alu . shiftLeft (prev_q ,1)
91 # temp2 expresses 2^-j in binary
92 temp2 = the_alu .point * "0" + (j -1)*"0" + "1" + "0"*( the_alu .bits - (j
-1) - the_alu .point -1 )
93
94 if( q_signed_digit == '1'):
95 return the_alu . twosCompl ( the_alu .add(temp1 ,temp2))
96 else:
97 return the_alu .sub(temp1 ,temp2)
98
99
100 def computeQfromSignedDigit (self ,prev_q , q_signed_digit ,j, the_alu ):
101 #temp expresses 2^-j in binary
102 temp = the_alu .point * "0" + (j -1)*"0" + "1" + "0"*( the_alu .bits - (j -1)
- the_alu .point -1 )
103 if ( q_signed_digit == '1'):
104 return the_alu .add(prev_q ,temp)
105 else:
106 return the_alu .sub(prev_q ,temp)
107
108 def npb(self ,num , point):
109 # nice print binary numbers
110 if point == None:
111 return num
112 else:
113 return num [: point ]+"."+num[point :]
114 def testResult (self , z,result , precision , the_alu ):
115 print("\n ============= Check Result ================ ")
37
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
116
117 # compute decimal input
118
119 print(z)
120 print( result )
121 decimal_input = int("0b"+z, 2)
122 decimal_input = decimal_input * 2**( -( the_alu .bits - the_alu .point))
123
124 result_decimal = int("0b"+result , 2)
125 result_decimal = result_decimal * 2**( -( the_alu .bits - the_alu .point))
126 result_decimal = result_decimal * 2** precision
127 print("The input in decimal : ", decimal_input )
128 print("The result decimal : ", result_decimal )
129 print("error: ", abs (( decimal_input )**0.5 - result_decimal ) )
130
38
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
220
221 # print (" one= ", one)
222 # print ("s= ", self.npb(prev_s , the_alu . point))
39
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
238
239 #sqrt1 = binSQRT ("10.00000000000000000000000000000")
240 sqrt1 = binSQRT (" 01.01101011 ")
241 sqrt1. nonRestoring ()
24 # open files
25 the_input = open( input_file_name , "w")
26 expected_adder_output = open( expected_adder_output_name , "w")
27 expected_mult_output = open( expected_mult_output_name , "w")
28
29 for i in range ( rns_base ):
30 input_1 = '{0:04b}'. format (i)
31 for k in range( rns_base ):
32 input_2 = '{0:04b}'. format (k)
33 """
34 compute the expexted output
35 """
36 mult_out = (i*k)% rns_base
37 mult_out_bin = '{0:04b}'. format ( mult_out )
38 add_out = (i + k)% rns_base
40
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
1 -- File: mult.vhd
2 -- Description : Modulo 9 multiplier
3 -- Schematic Author : Pietro Pennestri ( s2382660 )
4 -- VHDL file generated from the schematic with Deeds software .
5 -- Date: 4/4/2021
6 -- This VHDL file should be used for simulation
7 -- purpose only and does not necessarily be feasible for synthesis .
8
9 LIBRARY ieee;
10 USE ieee. std_logic_1164 .ALL;
11 USE ieee. numeric_std .all;
12
13
14 ENTITY mult IS
15 PORT(
16 -- ------------------------------------> Inputs :
17 iA: IN std_logic_vector ( 3 downto 0 );
18 iB: IN std_logic_vector ( 3 downto 0 );
19 -- ------------------------------------> Outputs :
20 oC: OUT std_logic_vector ( 3 downto 0 )
21 -- ----------------------------------------------------
22 );
23 END mult;
24
25
26 ARCHITECTURE structural OF mult IS
27
28 -- --------------------------------------> Components :
29 COMPONENT NOT_gate IS
30 PORT( I: IN std_logic ;
31 O: OUT std_logic );
32 END COMPONENT ;
33 --
34 COMPONENT AND2_gate IS
35 PORT( I0 ,I1: IN std_logic ;
36 O: OUT std_logic );
37 END COMPONENT ;
38 --
39 COMPONENT AND3_gate IS
40 PORT( I0 ,I1 ,I2: IN std_logic ;
41 O: OUT std_logic );
42 END COMPONENT ;
43 --
41
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
44 COMPONENT AND4_gate IS
45 PORT( I0 ,I1 ,I2 ,I3: IN std_logic ;
46 O: OUT std_logic );
47 END COMPONENT ;
48 --
49 COMPONENT OR3_gate IS
50 PORT( I0 ,I1 ,I2: IN std_logic ;
51 O: OUT std_logic );
52 END COMPONENT ;
53 --
54 COMPONENT OR4_gate IS
55 PORT( I0 ,I1 ,I2 ,I3: IN std_logic ;
56 O: OUT std_logic );
57 END COMPONENT ;
58 --
59 COMPONENT NOR3_gate IS
60 PORT( I0 ,I1 ,I2: IN std_logic ;
61 O: OUT std_logic );
62 END COMPONENT ;
63 --
64 COMPONENT Adder_Half IS
65 PORT( COUT:OUT std_logic ;
66 A: IN std_logic ;
67 B: IN std_logic ;
68 S: OUT std_logic );
69 END COMPONENT ;
70 --
71 COMPONENT Adder_Full IS
72 PORT( CIN: IN std_logic ;
73 COUT:OUT std_logic ;
74 A: IN std_logic ;
75 B: IN std_logic ;
76 S: OUT std_logic );
77 END COMPONENT ;
78
79 -- --------------------------------------> Signals :
80 SIGNAL S001: std_logic ;
81 SIGNAL S002: std_logic ;
82 SIGNAL S003: std_logic ;
83 SIGNAL S004: std_logic ;
84 SIGNAL S005: std_logic ;
85 SIGNAL S006: std_logic ;
86 SIGNAL S007: std_logic ;
87 SIGNAL S008: std_logic ;
88 SIGNAL S009: std_logic ;
89 SIGNAL S010: std_logic ;
90 SIGNAL S011: std_logic ;
91 SIGNAL S012: std_logic ;
92 SIGNAL S013: std_logic ;
93 SIGNAL S014: std_logic ;
94 SIGNAL S015: std_logic ;
95 SIGNAL S016: std_logic ;
96 SIGNAL S017: std_logic ;
97 SIGNAL S018: std_logic ;
98 SIGNAL S019: std_logic ;
99 SIGNAL S020: std_logic ;
100 SIGNAL S021: std_logic ;
101 SIGNAL S022: std_logic ;
102 SIGNAL S023: std_logic ;
103 SIGNAL S024: std_logic ;
42
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
155
156 BEGIN -- structural
157
158 -- --------------------------------------> Input:
159 S067 <= iA (0);
160 S068 <= iA (1);
161 S069 <= iA (2);
162 S070 <= iA (3);
163 S041 <= iB (0);
43
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
44
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
18 -- ------------------------------------------------------------------
19 ARCHITECTURE behavioral OF NOT_gate IS
20 BEGIN
21 O <= (not I);
22 END behavioral ;
23
24
25
26 -- ------------------------------------------------------------------
27 library ieee;
28 use ieee. std_logic_1164 .all;
29
30 ENTITY AND2_gate IS
31 PORT( I0 ,I1: IN std_logic ;
32 O: OUT std_logic );
33 END AND2_gate ;
34
35 -- ------------------------------------------------------------------
36 ARCHITECTURE behavioral OF AND2_gate IS
37 BEGIN
38 O <= (I0 and I1);
39 END behavioral ;
40
41
42 -- ------------------------------------------------------------------
43 library ieee;
44 use ieee. std_logic_1164 .all;
45
46 ENTITY AND3_gate IS
47 PORT( I0 ,I1 ,I2: IN std_logic ;
48 O: OUT std_logic );
49 END AND3_gate ;
45
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
50
51 -- ------------------------------------------------------------------
52 ARCHITECTURE behavioral OF AND3_gate IS
53 BEGIN
54 O <= (I0 and I1 and I2);
55 END behavioral ;
56
57
58 -- ------------------------------------------------------------------
59 library ieee;
60 use ieee. std_logic_1164 .all;
61
62 ENTITY AND4_gate IS
63 PORT( I0 ,I1 ,I2 ,I3: IN std_logic ;
64 O: OUT std_logic );
65 END AND4_gate ;
66
67 -- ------------------------------------------------------------------
68 ARCHITECTURE behavioral OF AND4_gate IS
69 BEGIN
70 O <= (I0 and I1 and I2 and I3);
71 END behavioral ;
72
73
74 -- ------------------------------------------------------------------
75 library ieee;
76 use ieee. std_logic_1164 .all;
77
78 ENTITY OR3_gate IS
79 PORT( I0 ,I1 ,I2: IN std_logic ;
80 O: OUT std_logic );
81 END OR3_gate ;
82
83 -- ------------------------------------------------------------------
84 ARCHITECTURE behavioral OF OR3_gate IS
85 BEGIN
86 O <= (I0 or I1 or I2);
87 END behavioral ;
88
89
90 -- ------------------------------------------------------------------
91 library ieee;
92 use ieee. std_logic_1164 .all;
93
94 ENTITY OR4_gate IS
95 PORT( I0 ,I1 ,I2 ,I3: IN std_logic ;
96 O: OUT std_logic );
97 END OR4_gate ;
98
99 -- ------------------------------------------------------------------
100 ARCHITECTURE behavioral OF OR4_gate IS
101 BEGIN
102 O <= (I0 or I1 or I2 or I3);
103 END behavioral ;
104
105
106 -- ------------------------------------------------------------------
107 library ieee;
108 use ieee. std_logic_1164 .all;
109
46
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
47
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
11
12 library ieee;
13 use ieee. std_logic_1164 .all;
14 use ieee. numeric_std .all;
15 use STD. textio .all;
16 use ieee. std_logic_textio .all;
17
18 entity tb_mult is
19
20 generic (
21 in_file_name : string := "data.in";
22 out_file_name : string := "data.out"
23 );
24
25 end tb_mult ;
26
27
48
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
82 begin
83
84 file_open ( file_VECTORS , in_file_name , read_mode );
85 file_open ( file_RESULTS , out_file_name , write_mode );
86
87 while not endfile ( file_VECTORS ) loop
88 readline ( file_VECTORS , v_ILINE );
89 read(v_ILINE , v_ADD_TERM1 );
90 read(v_ILINE , v_SPACE ); -- read in the space character
91 read(v_ILINE , v_ADD_TERM2 );
92
93 -- Pass the variable to a signal to allow the ripple - carry to use it
94 r_ADD_TERM1 <= v_ADD_TERM1 ;
95 r_ADD_TERM2 <= v_ADD_TERM2 ;
96
49
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
106 wait;
107 end process ;
108
109 end structure ;
110
111 -- -----------------------------------------------------------------------------
112 -- top level testbench (to bind generics )
113 -- -----------------------------------------------------------------------------
114
115 entity tb_mult_top is
116 end tb_mult_top ;
117
50
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
13
14 ENTITY adder IS
15 PORT(
16 -- ------------------------------------> Inputs :
17 iA: IN std_logic_vector ( 3 downto 0 );
18 iB: IN std_logic_vector ( 3 downto 0 );
19 -- ------------------------------------> Outputs :
20 oC: OUT std_logic_vector ( 3 downto 0 )
21 -- ----------------------------------------------------
22 );
23 END adder;
24
25
26 ARCHITECTURE structural OF adder IS
27
28 -- --------------------------------------> Components :
29 COMPONENT NOT_gate IS
30 PORT( I: IN std_logic ;
31 O: OUT std_logic );
32 END COMPONENT ;
33 --
34 COMPONENT AND2_gate IS
35 PORT( I0 ,I1: IN std_logic ;
36 O: OUT std_logic );
37 END COMPONENT ;
38 --
39 COMPONENT AND3_gate IS
40 PORT( I0 ,I1 ,I2: IN std_logic ;
41 O: OUT std_logic );
42 END COMPONENT ;
43 --
44 COMPONENT AND4_gate IS
45 PORT( I0 ,I1 ,I2 ,I3: IN std_logic ;
46 O: OUT std_logic );
47 END COMPONENT ;
48 --
49 COMPONENT OR3_gate IS
50 PORT( I0 ,I1 ,I2: IN std_logic ;
51 O: OUT std_logic );
52 END COMPONENT ;
53 --
54 COMPONENT BusMultiplexer21_4 IS
55
56 PORT( Q_03: OUT std_logic ;
57 Q_02: OUT std_logic ;
58 Q_01: OUT std_logic ;
59 Q_00: OUT std_logic ;
60 I0_03: IN std_logic ;
61 I0_02: IN std_logic ;
62 I0_01: IN std_logic ;
63 I0_00: IN std_logic ;
64 I1_03: IN std_logic ;
65 I1_02: IN std_logic ;
66 I1_01: IN std_logic ;
67 I1_00: IN std_logic ;
68 S0 : IN std_logic );
69 END COMPONENT ;
51
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
70 --
71 COMPONENT Adder_Half IS
72 PORT( COUT:OUT std_logic ;
73 A: IN std_logic ;
74 B: IN std_logic ;
75 S: OUT std_logic );
76 END COMPONENT ;
77 --
78 COMPONENT Adder_Full IS
79 PORT( CIN: IN std_logic ;
80 COUT:OUT std_logic ;
81 A: IN std_logic ;
82 B: IN std_logic ;
83 S: OUT std_logic );
84 END COMPONENT ;
85
86 -- --------------------------------------> Signals :
87 SIGNAL S001: std_logic ;
88 SIGNAL S002: std_logic ;
89 SIGNAL S003: std_logic ;
90 SIGNAL S004: std_logic ;
91 SIGNAL S005: std_logic ;
92 SIGNAL S006: std_logic ;
93 SIGNAL S007: std_logic ;
94 SIGNAL S008: std_logic ;
95 SIGNAL S009: std_logic ;
96 SIGNAL S010: std_logic ;
97 SIGNAL S011: std_logic ;
98 SIGNAL S012: std_logic ;
99 SIGNAL S013: std_logic ;
100 SIGNAL S014: std_logic ;
101 SIGNAL S015: std_logic ;
102 SIGNAL S016: std_logic ;
103 SIGNAL S017: std_logic ;
104 SIGNAL S018: std_logic ;
105 SIGNAL S019: std_logic ;
106 SIGNAL S020: std_logic ;
107 SIGNAL S021: std_logic ;
108 SIGNAL S022: std_logic ;
109 SIGNAL S023: std_logic ;
110 SIGNAL S024: std_logic ;
111 SIGNAL S025: std_logic ;
112 SIGNAL S026: std_logic ;
113 SIGNAL S027: std_logic ;
114 SIGNAL S028: std_logic ;
115 SIGNAL S029: std_logic ;
116 SIGNAL S030: std_logic ;
117 SIGNAL S031: std_logic ;
118 SIGNAL S032: std_logic ;
119 SIGNAL S033: std_logic ;
120 SIGNAL S034: std_logic ;
121 SIGNAL S035: std_logic ;
122 SIGNAL S036: std_logic ;
123 SIGNAL S037: std_logic ;
124 SIGNAL S038: std_logic ;
125 SIGNAL S039: std_logic ;
126 SIGNAL S040: std_logic ;
127 SIGNAL S041: std_logic ;
128 SIGNAL S042: std_logic ;
129 SIGNAL S043: std_logic ;
52
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
133
134 BEGIN -- structural
135
136 -- --------------------------------------> Input:
137 S014 <= iA (0);
138 S013 <= iA (1);
139 S012 <= iA (2);
140 S011 <= iA (3);
141 S018 <= iB (0);
142 S016 <= iB (1);
143 S017 <= iB (2);
144 S015 <= iB (3);
145
146 -- --------------------------------------> Output :
147 oC (0) <= S042;
148 oC (1) <= S043;
149 oC (2) <= S044;
150 oC (3) <= S045;
151
152 -- --------------------------------------> Constants :
153 S009 <= '1';
154 S010 <= '0';
155
156 -- --------------------------------------> Component Mapping :
157 C002: Adder_Full PORT MAP ( S002 , S001 , S011 , S015 , S005 );
158 C003: Adder_Full PORT MAP ( S003 , S002 , S012 , S017 , S006 );
159 C004: Adder_Full PORT MAP ( S004 , S003 , S013 , S016 , S007 );
160 C005: Adder_Half PORT MAP ( S004 , S014 , S018 , S008 );
161 C011: BusMultiplexer21_4 PORT MAP ( S045 , S044 , S043 , S042 ,
162 S041 , S040 , S039 , S038 ,
163 S010 , S009 , S009 , S009 ,
164 S001 );
165 B1_C048 : AND4_gate PORT MAP ( S019 , S021 , S005 , S020 , S041 );
166 B1_C049 : NOT_gate PORT MAP ( S006 , S019 );
167 B1_C050 : NOT_gate PORT MAP ( S007 , S021 );
168 B1_C051 : NOT_gate PORT MAP ( S008 , S020 );
169 B1_C082 : OR3_gate PORT MAP ( S024 , S023 , S022 , S040 );
170 B1_C083 : NOT_gate PORT MAP ( S005 , S025 );
171 B1_C084 : AND2_gate PORT MAP ( S006 , S025 , S022 );
172 B1_C085 : AND2_gate PORT MAP ( S007 , S006 , S024 );
173 B1_C086 : AND2_gate PORT MAP ( S008 , S006 , S023 );
174 B1_C126 : OR3_gate PORT MAP ( S028 , S029 , S030 , S039 );
175 B1_C127 : OR3_gate PORT MAP ( S033 , S034 , S032 , S038 );
176 B1_C139 : AND2_gate PORT MAP ( S007 , S031 , S030 );
177 B1_C140 : AND2_gate PORT MAP ( S007 , S008 , S028 );
178 B1_C141 : AND4_gate PORT MAP ( S027 , S006 , S026 , S005 , S029 );
179 B1_C142 : NOT_gate PORT MAP ( S008 , S027 );
180 B1_C143 : NOT_gate PORT MAP ( S007 , S026 );
181 B1_C185 : NOT_gate PORT MAP ( S005 , S031 );
182 B1_C192 : AND3_gate PORT MAP ( S007 , S005 , S037 , S033 );
183 B1_C193 : AND2_gate PORT MAP ( S008 , S036 , S032 );
184 B1_C199 : NOT_gate PORT MAP ( S005 , S036 );
185 B1_C200 : NOT_gate PORT MAP ( S008 , S037 );
186 B1_C201 : AND3_gate PORT MAP ( S006 , S035 , S005 , S034 );
187 B1_C202 : NOT_gate PORT MAP ( S008 , S035 );
188 END structural ;
53
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
17 -- ------------------------------------------------------------------
18 ARCHITECTURE behavioral OF NOT_gate IS
19 BEGIN
20 O <= (not I);
21 END behavioral ;
22
23
24
25 -- ------------------------------------------------------------------
26 library ieee;
27 use ieee. std_logic_1164 .all;
28
29 ENTITY AND2_gate IS
30 PORT( I0 ,I1: IN std_logic ;
31 O: OUT std_logic );
32 END AND2_gate ;
33
34 -- ------------------------------------------------------------------
35 ARCHITECTURE behavioral OF AND2_gate IS
36 BEGIN
37 O <= (I0 and I1);
38 END behavioral ;
39
40
41 -- ------------------------------------------------------------------
42 library ieee;
43 use ieee. std_logic_1164 .all;
44
45 ENTITY AND3_gate IS
46 PORT( I0 ,I1 ,I2: IN std_logic ;
47 O: OUT std_logic );
48 END AND3_gate ;
49
50 -- ------------------------------------------------------------------
51 ARCHITECTURE behavioral OF AND3_gate IS
52 BEGIN
53 O <= (I0 and I1 and I2);
54 END behavioral ;
55
56
57 -- ------------------------------------------------------------------
58 library ieee;
59 use ieee. std_logic_1164 .all;
60
61 ENTITY AND4_gate IS
54
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
77 ENTITY OR3_gate IS
78 PORT( I0 ,I1 ,I2: IN std_logic ;
79 O: OUT std_logic );
80 END OR3_gate ;
81
82 -- ------------------------------------------------------------------
83 ARCHITECTURE behavioral OF OR3_gate IS
84 BEGIN
85 O <= (I0 or I1 or I2);
86 END behavioral ;
87
88
89 -- ------------------------------------------------------------------
90 library ieee;
91 use ieee. std_logic_1164 .all;
92
93 ENTITY BusMultiplexer21_4 IS
94
55
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
122
123 -- ------------------------------------------------------------------
124 library ieee;
125 use ieee. std_logic_1164 .all;
126
127 ENTITY Adder_Half IS
128 PORT( COUT:OUT std_logic ;
129 A: IN std_logic ;
130 B: IN std_logic ;
131 S: OUT std_logic );
132 END Adder_Half ;
133
134 -- ------------------------------------------------------------------
135 ARCHITECTURE behavioral OF Adder_Half IS
136 SIGNAL AB: std_logic_vector ( 1 downto 0 );
137 BEGIN
138 AB <= A & B;
139 --
140 with AB select
141 S <= '0' when "00",
142 '1' when "01",
143 '1' when "10",
144 '0' when "11",
145 'X' when others ;
146 --
147 with AB select
148 COUT <= '0' when "00",
149 '0' when "01",
150 '0' when "10",
151 '1' when "11",
152 'X' when others ;
153 END behavioral ;
154
155 -- ------------------------------------------------------------------
156 library ieee;
157 use ieee. std_logic_1164 .all;
158
159 ENTITY Adder_Full IS
160 PORT( CIN: IN std_logic ;
161 COUT:OUT std_logic ;
162 A: IN std_logic ;
163 B: IN std_logic ;
164 S: OUT std_logic );
165 END Adder_Full ;
166
167 -- ------------------------------------------------------------------
168 ARCHITECTURE behavioral OF Adder_Full IS
169 SIGNAL ABC: std_logic_vector ( 2 downto 0 );
170 BEGIN
171 ABC <= A & B & CIN;
172 --
173 with ABC select
174 S <= '0' when "000",
175 '1' when "001",
176 '1' when "010",
177 '0' when "011",
178 '1' when "100",
179 '0' when "101",
180 '0' when "110",
181 '1' when "111",
56
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
10
11 library ieee;
12 use ieee. std_logic_1164 .all;
13 use ieee. numeric_std .all;
14 use STD. textio .all;
15 use ieee. std_logic_textio .all;
16
17 entity tb_adder is
18
19 generic (
20 in_file_name : string := "data.in";
21 out_file_name : string := "data.out"
22 );
23
24 end tb_adder ;
25
26
27 architecture structure of tb_adder is
28
29 -- ---------------------------------------------------------------------------
30 -- Declare the Adder
31 -- ---------------------------------------------------------------------------
32 component adder is
33 port (
34 -- ------------------------------------> Inputs :
35 iA: IN std_logic_vector ( 3 downto 0 );
36 iB: IN std_logic_vector ( 3 downto 0 );
37 -- ------------------------------------> Outputs :
38 oC: OUT std_logic_vector ( 3 downto 0 )
39 -- ----------------------------------------------------
40 );
41 end component adder;
42
43
44 -- ---------------------------------------------------------------------------
45 -- Testbench Internal Signals
46 -- ---------------------------------------------------------------------------
47 file file_VECTORS : text;
57
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
81 begin
82
83 file_open ( file_VECTORS , in_file_name , read_mode );
84 file_open ( file_RESULTS , out_file_name , write_mode );
85
86 while not endfile ( file_VECTORS ) loop
87 readline ( file_VECTORS , v_ILINE );
88 read(v_ILINE , v_ADD_TERM1 );
89 read(v_ILINE , v_SPACE ); -- read in the space character
90 read(v_ILINE , v_ADD_TERM2 );
91
92 -- Pass the variable to a signal to allow the ripple - carry to use it
93 r_ADD_TERM1 <= v_ADD_TERM1 ;
94 r_ADD_TERM2 <= v_ADD_TERM2 ;
95
96 wait for 60 ns;
97
98 write(v_OLINE , w_SUM , right , 4);
99 writeline ( file_RESULTS , v_OLINE );
100 end loop;
101
102 file_close ( file_VECTORS );
103 file_close ( file_RESULTS );
104
105 wait;
106 end process ;
107
58
Gedownload door Nishad Mandlik (mandliksg@gmail.com)
lOMoARcPSD|24554605
Honor Pledge
I promise that I have not used unauthorised help from people or other sources
for completing my exam. I created the submitted answers all by myself during
the time slot that was allocated for that specific exam part.
Pietro Pennestrì
59
Gedownload door Nishad Mandlik (mandliksg@gmail.com)