======== START LECTURE #10 ========

> I have a question about the first lab; I'm not sure how we
> would implement a mux, would a series of if-else
> statements be an acceptable option?

No.  But that is a good question.  if-then-elif...-else
would be a FUNCTIONAL simulation.  That is you are
simulating what the mux does but not HOW it does it.  For a
gate level simulation, you need to implement the mux in
terms of AND, NOT, OR, XOR and then write code link
Fulladder.c

The implementation of a two way mux in terms of AND OR NOT
is figure B.4 on page B-9 of the text.  You need to do a 3
way mux.

Homework: (for fun) prove this last statement (4.29)

addu, subu, addiu

These add and subtract the same the same was as add and sub, but do not signal overflow

4.4: Logical Operations

Shifts: sll, srl

Bitwise AND and OR: and, or, andi, ori

No surprises.

4.5: Constructing an ALU--the fun begins

First goal is 32-bit AND, OR, and addition

Recall we know how to build a full adder. Will draw it as

With this adder, the ALU is easy.

32-bit version is simple.

  1. Use an array of logic elements for the logic. The logic element is the 1-bit ALU
  2. Use buses for A, B, and Result.
  3. ``Broadcast'' Opcode to all of the internal 1-bit ALUs. This means wire the external Opcode to the Opcode input of each of the internal 1-bit ALUs

First goal accomplished.

How about subtraction?

1-bit ALU with ADD, SUB, AND, OR is

For subtraction set Binvert and Cin.

32-bit version is simply a bunch of these.

Simulating Combinatorial Circuits at the Gate Level

Write a procedure for each logic box with the following properties.

Handout: FullAdder.c and FourBitAdder.c.

Lab 1: Do the equivalent for 1-bit-alu (without subtraction). This is easy. Lab 2 will be similar but for a more sophisticated ALU.

Extra requirements for MIPS alu:

  1. slt set-less-than





  2. Why isn't this method used?

  3. Ans: It is wrong!

  4. Example using 3 bit numbers (i.e. -4 .. 3). Try slt on -3 and +2. True subtraction (-3 - +2) give -5. The negative sign in -5 indicates (correctly) that -3 < +2. But three bit subtraction -3 - +2 gives +3 ! Hence we will incorrectly conclude that -3 is NOT less than +2. (Really, it signals an overflow. unless doing unsigned)

  5. Solution: Need the correct rule for less than (not just sign of subtraction)

    Homework: figure out correct rule, i.e. prob 4.23. Hint: when an overflow occurs the sign bit is definitely wrong (so the complement of the sign bit is right).

    1. Overflows
      • The HOB is already unique (outputs SET)
      • Need to enhance it some more to produce the overflow output
      • Recall that we gave the rule for overflow: you need to examine
        • Whether add or sub (binvert)
        • The sign of A
        • The sign of B
        • The sign of the result
        • Since this is the HOB we have all the sign bits.
        • The book also uses Cout, but this appears to be an error



    2. Simpler overflow detection
      • An overflow occurs if and only if the carry in to the HOB differs from the carry of of the HOB



    3. Zero Detect
      • To see if all bits are zero just need NOR of all the bits
      • Conceptually trivially but does require some wiring

    4. Observation: The initial Cin and Binvert are always the same. So just use one input called Bnegate.

    The Final Result is

    Symbol for the alu is

    What are the control lines?

    What functions can we perform?

    What (3-bit) values for the control lines do we need for each function?
    and000
    or 0 01
    add 0 10
    sub 1 10
    slt 1 11