Beruflich Dokumente
Kultur Dokumente
February 2015
Numeric Basics
3710 = 1 25 + 0 24 + 0 23 + 1 22 + 0 21 + 1 20 .
3710 = 1001012 .
n bits : 0 2n 1.
Unsigned Integers
Assignments
Legal: s_unsig <= "1110";
Illegal: s_unsig <= 0;
Legal: s_unsig_dest <= s_unsig+1;
Conversions
I
Assignments
Resizing an unsigned integer
signal a : unsigned (3 downto 0);
signal b : unsigned (7 downto 0);
b <= " 0000 " & a ;
a <= b (3 downto 0);
Concatenation operator:
&
Alternate way
signal a : unsigned (3 downto 0);
signal b : unsigned (7 downto 0);
b <= resize (a ,8);
a <= resize (b ,4);
0
1
0
0
1
0
1
0
0
1
0
0
1
1
0
0
1
1
0
0
0
xi
yi
1
0
1
Implementation
xn1 yn1
cn
sn
full
adder
sn1
cn1
ci+1
full
adder
si
x1
ci
c2
y1
full
adder
s1
x0
c1
y0
full
adder
c0
s0
Adders
Fast-carry-chain adder
I
xi
yi
pi
ci+1
pi = xi yi
gi
g i = xi yi
ci
ci +1 = g i + pi ci
si = pi ci
si
si = pi xor c_in;
co = gi or pi and c_in;
Carry-lookahed generator
I
x3
y3
x2
y2
x1
y1
x0
y0
c4 = g3 or (p3 and g 2)
or (p3 and p2 and g1)
or (p3 and p2 and p1 and g 0)
or (p3 and p2 and p1 and p0 and c0)
c4
p3
g2
p2
g1
p1
g0
carry-lookahead generator
p3
s3
c3
p2
s2
c2
p1
s1
c1
p0
s0
p0
c0
Adder in VHDL
library ieee ;
use ieee . std_log ic_1164 . all ;
use ieee . numeric_std . all ;
...
signal a ,b , s : unsigned (3 downto 0);
...
s <= a + b ;
I
library ieee ;
use ieee . std_log ic_1164 . all ;
use ieee . numeric_std . all ;
...
signal a ,b , s : unsigned (7 downto 0);
signal temp : unsigned (8 downto 0); -- MSB : carry
signal c_out : std_logic ;
...
temp <= ( 0 & a ) + ( 0 & b ); -- compute sum with 9 bits
s
<= temp (7 downto 0);
-- true sum is in LSBs
c_out <= temp (8);
-- carry is the MSB
xn2
yn2
gt
xn1 = yn1
xn20 > yn20
xn2 = yn2
x1 > y1
x0
y0
x0 > y0
x1 = y1
x1
y1