Top Banner
The Karnaugh Map
48
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • The Karnaugh Map

  • Simplifying Digital CircuitsReconsider the 1-bit full adder. The carry bit is

    But we can implement the function with a much simpler circuit:

    How to get there?

  • Simplifying digital circuitThere are many methods. Using boolean algebraUsing K-mapBy just being really smart

  • *Boolean Algebra Laws A+A=A, A*A=A

    *CDA3100 week09-1.ppt*

  • Boolean AlgebraTo use Boolean algebra, note that CO= abc+abc+abc+abcNow, abc+abc=ab(c+c)=ab.abc+abc=ac(b+b)=acabc+abc=bc(a+a)=bcWe used term abc three times because abc=abc+abc+abc!

  • K-mapIt is actually more convenient to use K-map to simplify digital circuits.K-map is a very mechanical procedure. Nothing fancy. It basically uses two rules: A+A=A, and AB+AB=A.

  • K-mapK-map

    CO = ab + ac + bc

    0001111001abc

    00100111

  • K-map rulesDraw the K-map. Remember to make sure that the adjacent rows/columns differ by only one bit.According to the truth table, write 1 in the boxes.Draw a circle around a rectangle with all 1s. The rectangle must have size (1),2,4,8,16Then, reduce the terms by writing down the variables whose values do not change. For example, if there is a rectangle with two 1s representing abc and abc, you write a term as ab. A term may be covered in multiple circles.The rectangle can wrap-around!Simplify to the simplest circuits possible. Usually it means the minimum number of circles, i.e., minimum number of terms in the equation. The terms should also contain as few variables as possible.

  • K-mapF=abc+abc+abc+abc

    0001111001abc

    01001101

  • K-mapF=abc+abc+abc+abc

    F=ab+bc

    0001111001abc

    01001101

  • K-mapF=abc+abc+abc+abc+abc

    0001111001abc

    0110111

  • K-mapF=abc+abc+abc+abc+abc

    F=b+ac

    0001111001abc

    0110111

  • K-mapF=abcd+abcd+abcd+abcd+abcd+abcd

    000111100001abcd1110

    111111

  • K-mapF=abcd+abcd+abcd+abcd+abcd+abcd

    F=bd+acd+abc

    000111100001abcd

    1110

    111111

  • In class exercise Design a selector?I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if s=1, f=b.

  • Selector

    sabf00000010010101111000101111001111

  • K-mapF=sab+sab+sab+sab

    0001111001sab

    0100111

  • K-mapF=sab+sab+sab+sab

    F=sa+ab

    0001111001sab

    0100111

  • Building from the adder to ALUALU Arithmetic Logic Unit, does the major calculations in the computer, including Add AndOrSubIn MIPS, the ALU takes two 32-bit inputs and produces one 32-bit output, plus some additional signalsAdd is only one of the functions, and in this lecture, we are going to see how an full ALU is designed

  • ALU

  • Review1-bit full adder

  • 32-bit adder

  • Building 32-bit ALU with 1-bit ALU Build 32-bit ALU with 1-bit ALU. Deal with the easy ones first and and or

  • And and Or operationsAnd

    abAnd result

    Or

    abOr result

  • Putting them togetherSometimes the instruction is add, sometimes it is or, sometimes is and, how to put them together? In MIPS instructions, there are many fields: op, funct, rs, rt, rd, shamt

  • Putting them togetherJust do everything (add, and, or) and then select one AS the output with a selector.

  • Subtraction?How to implement subtraction?

  • *SubtractionUsing twos complement representation, we can implement subtraction through addition

    The reason is that a negative number -b in 2s complement is actually 2n-b. So if you do a+2n-b and take only the lower n bits, it becomes a-b because 2n is a one bit at bit n (bit indices are 0,1,2,, n-1, n).What do we need to add to the ALU we have in order to be able to perform subtraction?

  • *1-Bit ALU That can Do SubtractionTo do a-b, three things:Invert every bit of b.Add 1.Add with a.So, if it is a subtraction, invert the second operand, set the CarryIn of the last one-bit full adder to be 1, then select the adder output.

  • SubtractionNotice that every time we want the ALU to subtract, we set both CarryIn and Binvert to 1. For add or logical operations, we want both control lines to be 0. We can therefore simplify control of the ALU by combining the CarryIn and Binvert to a single control line called Bnegate.

  • *Supporting Set Less ThanSet less than instruction produces 1 if rs < rt, and 0 otherwiseIt needs to set all but the least significant bit to 0The least significant bit is set according to the comparisonWhich can be done using subtraction

    That is, do a subtraction, check the sign bit (bit 31).

  • *ComplicationIf we only use the sign bit of the adder, sometimes we will be wrongFor the following example (using 4 bits only), we have

    Then we have , which is clearly wrong

  • OverflowThe problem is that sometimes we have overflow. If we have only 4 bits, a number greater than 7 or a number less than -8 will cause an overflow because it cannot be represented in 4 bits.In the previous example, -7-6=-13, overflowed.

  • Dealing with overflowOverflow happens when the two numbers are of the same sign. If they are of different signs, the addition result will be less than the larger one (the absolute value) and should be still within the range, assuming the two original numbers are within the range.

  • *Overflow DetectionOne way to detect overflow is to check whether the sign bit is consistent with the sign of the inputs when the two inputs are of the same sign if you added two positive numbers and got a negative number, something is wrong, and vice versa.

  • Dealing with overflowFor two positive numbers, after the addition, The carryout of ALU31 must be 0, because in 2s complement, positive numbers go from 0001 to 011..1. The largest number is 0111 and adding two 0111 will lead to 11110, the carry out is still 0. if no overflow, the sign bit (bit 31) should be 0, because the result is a positive number.If overflowed, the sign bit (bit 31) will be 1, caused by a carryin to ALU31.

  • Dealing with overflowFor two negative numbers, after the addition, The carryout of ALU31 must be 1, because in 2s complement, negative numbers go from 1000 to 111..1. Even if you are just adding two 1000, you will have 100000, the carry out is 1. if no overflow, the sign bit (bit 31) should be 1, because the result is a negative number.If overflowed, the sign bit (bit 31) will be 0, caused by having no carryin to ALU31.

  • *Overflow DetectionLets check the most significant bit more carefully

  • *Overflow DetectionThe result shows that we can detect the overflow by checking if the CarryIn and CarryOut of the most significant bit are different

  • *OverflowThe sign bit is correct if there is no overflowIf there is overflow, the sign bit will be wrong and needs to be inverted

  • *Supporting Set Less Than

  • *32-bit ALU that Supports Set Less Than

  • *The Corrected Most Significant Bit Unit

  • *Supporting Branch InstructionsWe need to be able to test if two numbers are the same

  • Final 32-Bit ALU

  • *Final 32-Bit ALUALU control lines are 1-bit Ainvert line, 1-bit Bnegate line, and 2-bit operation lines

  • *ALU Symbol

    *CDA3100 week09-1.ppt*