Download - Digital Logic Design Lecture # 12 University of Tehran.

Transcript
Page 1: Digital Logic Design Lecture # 12 University of Tehran.

Digital Logic Design

Lecture # 12University of Tehran

Page 2: Digital Logic Design Lecture # 12 University of Tehran.

Outline

Adders Subtractor Designing Example Hard wares

Using the Standard Packages ALU (Arithmetic Logic Unit) Verilog

Page 3: Digital Logic Design Lecture # 12 University of Tehran.

Adders Consider the following addition process:

Observing this addition as a slice by slice process, we could realize the whole process by realizing one of the slices in hardware, that is by designing a hardware that would add two bits and the carry from the last slice and generate a sum and a carry out. As we saw in the last sessions, this logic would give:

incbas ininout cbcabac ...

1 0 1 11 1 0 1

1 1 0 0 0

Page 4: Digital Logic Design Lecture # 12 University of Tehran.

Adders (continued…) And the logic diagram of our design was:

ab

ci

co

s

Page 5: Digital Logic Design Lecture # 12 University of Tehran.

Adders (continued…) As mentioned in the last session if we want to

do a 4 bit addition we could simply use four full adders next to each other creating a ripple carry adder:

F.A. F.A. F.A. F.A.

a0b3 a3 b2 a2 b1 a1 b0

S3 S2 S1 S0

0

Cout

Page 6: Digital Logic Design Lecture # 12 University of Tehran.

Adders (continued…) We could use a half adder for the addition of the

rightmost bit because this stage’s carry in as always 0.

But the fact that using a half adder instead of a full adder for the first bit stage will not give us a considerable amount of extra space must be taken into consideration.

F.A. F.A. F.A. H.A.

a0b3 a3 b2 a2 b1 a1 b0

S3 S2 S1 S0Cout

Page 7: Digital Logic Design Lecture # 12 University of Tehran.

Adders (continued…) Looking at our design it is rather obvious that

this design could result in a very big delay time if used for a large number of bits. For instance if each and/or gate had a delay of 5ns this would result in a 40ns delay in a 4 bit ripple carry adder. To solve the above problem, we need a design where each cell can predict its own carry and with a timing overhead for this prediction, our result could be ready in 15ns. This design is named carry look ahead.

Page 8: Digital Logic Design Lecture # 12 University of Tehran.

Adders (continued…) Another very simple method that can help in

increasing speed of our addition and decreasing delay times is to make each cell a little more complex and do the addition 2 bits by 2 bits. In such a case because we still are using 2 level networks the delay on each cell will still be 10ns. We can’t use this method for larger cells than 2 bits at a time because the size of the hardware would make it impractical.

2 levelco ci

a0b1 a1 b0

S1 S0

Page 9: Digital Logic Design Lecture # 12 University of Tehran.

Adders (continued…) 74283: This adder does addition using the

carry look ahead method but this isn’t the case when cascading these packages.

1

A 1

C IN

A 3

B 2

A 2

B 1

B 4

A 4

B 3C O U T

S U M 4

S U M 3

S U M 2

S U M 1

7 4 2 8 3

4 B IT A D D E R

Page 10: Digital Logic Design Lecture # 12 University of Tehran.

Subtractor As we saw before, one of the features of the

2’s complement system was that the addition and subtraction processes were very much the same. We can perform subtraction by simply inverting the bits of one operand and setting the carry in bit of the operation to 1.

adder

a0b3 a3 b2 a2 b1 b0a1

1)1()( bababa

Page 11: Digital Logic Design Lecture # 12 University of Tehran.

Subtractor (continued…) In order to be able to use one package for both

addition and subtraction, we can use XOR gates as controllable inverters. These packages have the following structure:

adder

a0

b3

a3

b2

a2

b1 b0

a1

add/sub

cin

Page 12: Digital Logic Design Lecture # 12 University of Tehran.

Subtractor (continued…) Let’s now design a structure that can give us

the and result of the two inputs or the add/sub result based on a select line.

S3 S2 S1 S0

adder

a0

b3

a3

b2

a2

b1 b0

a1

0 1 0 10 10 1

And select

add/sub

Page 13: Digital Logic Design Lecture # 12 University of Tehran.

Subtractor (continued…) As you can see in the last example, four 2-to-1

multiplexers with a common select are used to give us the needed result based on the value of the select line.

Page 14: Digital Logic Design Lecture # 12 University of Tehran.

Designing Example Hard wares Using the Standard Packages Let’s use the packages we’ve seen so far to

design a hardware that converts a 2’s complement number to its equivalent sign and magnitude form. This means that a conversion will take place whenever the MSB is 1 that in when our number is negative (positive numbers need no conversion).

8 bitadder

a[6:0]7

0 a7

b[7:0]8

0

7A[6:0]A7

7r[6:0] R[6:0]

r7 R7

cin

Page 15: Digital Logic Design Lecture # 12 University of Tehran.

ALU (Arithmetic Logic Unit) An ALU is a component that can do both

arithmetic and logic operations on its inputs. It can also have a comparator inside that gives outputs such as overflow flag, zero flag etc as well as its operation results.

Note: The adders inside an ALU are usually carry look ahead adders and in order to be able to cascade adders and keep this feature in them, they have outputs that can help in prediction of the next stages carry in bits. These outputs are usually called ‘p’ and ‘g’.

Page 16: Digital Logic Design Lecture # 12 University of Tehran.

ALU (Arithmetic Logic Unit) (continued…) 74181: In this package, four select lines

choose the function performed by the ALU, as shown in the following table. This ALU has ‘g’ and ‘p’ outputs that keeps addition carry look ahead even after cascading.

2

A 0 N

B 0 N

A 1 N

B 1 N

A 2 N

B 2 N

A 3 N

B 3 N

C N

M

S 0

S 1

S 2

S 3

G N

P N

F 0 N

F 1 N

F 3 N

F 2 N

C N 4

A E Q B

7 4 1 8 1

A L U

Page 17: Digital Logic Design Lecture # 12 University of Tehran.

Verilog Consider the following Verilog code:

module max(a, b, z);input [3:0] a, b;output [3:0] z;

assign z=(a>b)?a:b;endmodule

This kind of description is called data flow

description that can be given to a synthesis tool which will give us a hadware realization for it.

Page 18: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) The following code is the code for an adder

subtractor module:module addsub(a, b, select, cout, sum);

input [7:0] a, b;input select;

output [7:0] sum;output cout;

assign {cout, sum}=select?(a-b):(a+b);endmodule

Page 19: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) An adder with overflow detection:

module adder(a, b, cin, sum, cout, ov); input [7:0] a, b; input cin; output [7:0] sum; output cout, ov; assign {cout, sum}=a+b+cin; assign ov=a[7]&b[7]&~sum[7] |

~a[7]&~b[7]&sum[7]; endmodule

Page 20: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) When writing Verilog code for different

problems many a time can occur where writing assign statements using condition expressions can become very complex. In such cases ‘always block’ is used. Pay attention to the following example in the next slide.

Page 21: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) Example: module ALU(a, b, s, z);

input [7:0] a, b;input [1:0] s; output [7:0] z;reg [7:0] z;always @(a, b, s) begin

if (s==0) z=a+b; else if(s=1) z=a-b;else if(s=2) z=a&b;else z=a^b;endendmodule

Page 22: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) Note: The list of variables given in parentheses

in front of ‘always @’ are called the sensitivity list. As we know a combinational circuit changes its output whenever one of its inputs change, that is the inputs to that circuit are its sensitivity list. This syntax is different for sequential circuits as we will see later on.

Page 23: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) An important issue that must be noted here is

that when describing a circuit for synthesis (as the examples we saw today) we do not use any timings in our code. This is because the software is going to use certain hardware for the design and thus we are not in a situation to be able to issue any delay times.

We use Verilog for two main reasons: Synthesis Modeling for simulation

Page 24: Digital Logic Design Lecture # 12 University of Tehran.

Verilog (continued…) When using Verilog for synthesis we do not

issue delay times (that is it is ignored even if we do). But when modeling for simulation or when we’re using particular packages we know about, we must issue delay times in order for the simulation wave forms to be something near to results we will get in reality.