Verlogic3 Chapter3
Verlogic3 Chapter3
Number Representation
and
Arithmetic Circuits
Binary numbers
Unsigned numbers
• all bits represent the magnitude of a positive
integer
!
Signed numbers
• left-most bit represents the sign of a number
Table 3.1. Numbers in different systems.
Please see “portrait orientation” PowerPoint file for Chapter 3
ci
si
xi
yi
ci + 1
c1
cn FA cn ” 1 c2 FA FA c0
sn – 1 s1 s0
MSB position LSB position
Magnitude
MSB
bn – 1 bn – 2 b1 b0
Magnitude
Sign
0 denotes +
1 denotes – MSB
For a positive n-bit number P, let K1 and K2 denote its 1’s and 2’s
complements, respectively.
K1 = (2n – 1) – P
K2 = 2n – P
(+ 5) 0101 (– 5) 1010
+ – 2)
( +1101 + (– 2) +1101
(+ 3) 10 0 1 0 (– 7) 10111
1 1
0011 1000
( + 5) 0101 ( –5 ) 1011
+ ( –2 ) + 1110 + (–2 ) + 1110
( + 3) 1 0011 ( –7 ) 11001
ignore ignore
ignore
( –5 ) 1011 1011
– ( + 2) – 0010 + 1110
( –7 ) 11001
ignore
( + 5) 0101 0101
– ( –2 ) – 1110 + 0010
( + 7) 0111
( –5 ) 1011 1011
– ( –2 ) – 1110 + 0010
( –3 ) 1101
Add ⁄ Sub
control
xn – 1 x1 x0
cn n-bit adder c0
sn – 1 s1 s0
( + 7) 0111 ( –7 ) 1001
+ (– 2 ) + 1110 + (–2 ) + 1110
( + 5) 1 0101 ( –9 ) 10111
c4 = 1 c4 = 1
c3 = 1 c3 = 0
g1 p1 g0 p0
c1
c2 c0
Stage 1 Stage 0
s1 s0
x0 y0
g1 p1 g0 p0
c0
c2
c1
s1 s0
c8
c32 Block c24 c16 Block Block c0
3 1 0
s31 – 24 s15 – 8 s7 – 0
G3 P3 G1 P1 G0 P0
s 31 – 24 s 15 – 8 s7 – 0
c 32 c 16 c8
Second-level lookahead
endmodule
Figure 3.18. Verilog code for the full-adder using gate level
primitives.
module fulladd (Cin, x, y, s, Cout);
input Cin, x, y;
output s, Cout;
endmodule
assign s = x ^ y ^ Cin;
assign Cout = (x & y) | (x & Cin) | (y & Cin);
endmodule
assign s = x ^ y ^ Cin,
Cout = (x & y) | (x & Cin) | (y & Cin);
endmodule
endmodule
assign s = x ^ y ^ Cin,
assign Cout = (x & y) | (x & Cin) | (y & Cin);
endmodule
endmodule
endmodule
endmodule
endmodule
endmodule
Figure 3.28. An alternative specification of an n-bit adder with carry-out and overflow
signals.
module addern (carryin, X, Y, S, carryout, overflow);
parameter n = 32;
input carryin;
input [n-1:0] X, Y;
output reg [n-1:0] S;
output reg carryout, overflow;
endmodule
endmodule
endmodule
endmodule
S E M
Sign
0 denotes + 8-bit 23 bits of mantissa
1 denotes – excess-127
exponent
64 bits
S E M
Sign
11-bit excess-1023 52 bits of mantissa
exponent
endmodule
xi pi si
V DD
yi gi
ci + 1
always @(IN)
if (IN == 4'b0101) OUT = 4'b0001;
else if (IN == 4'b0110) OUT = 4'b0010;
else if (IN == 4'b0111) OUT = 4'b0011;
else if (IN == 4'b1001) OUT = 4'b0010;
else if (IN == 4'b1010) OUT = 4'b0100;
else if (IN == 4'b1011) OUT = 4'b0110;
else if (IN == 4'b1101) OUT = 4'b0011;
else if (IN == 4'b1110) OUT = 4'b0110;
else if (IN == 4'b1111) OUT = 4'b1001;
else OUT = 4'b0000;
endmodule