Docsity

Arithmetic-Logic Units: Building Blocks of Processors, Summaries of Logic

Partial preview of the text

Download Arithmetic-Logic Units: Building Blocks of Processors and more Summaries Logic in PDF only on Docsity!

Unit 10

Arithmetic-logic units

College of Computer and Information Sciences Department of Computer Science

CSC 220: Computer Organization

Remember:

The four-bit adder

  • The basic four-bit adder always computes S = A + B + CI.
  • But by changing what goes into the adder inputs A, B and CI, we can change the adder output S.
  • This is also what we did to build the combined adder-subtractor circuit.

It’s the adder-subtractor again!

  • Here the signal Sub and some XOR gates alter the adder inputs.
    • When Sub = 0, the adder inputs A, B, CI are Y, X, 0, so the adder produces G = X + Y + 0, or just X + Y.
    • When Sub = 1, the adder inputs are Y’, X and 1, so the adder output is G = X + Y’ + 1, or the two’s complement operation X - Y.

Modifying the adder inputs

  • By following the same approach, we can use an adder to compute other functions as well.
  • We just have to figure out which functions we want, and then put the right circuitry into the “Input Logic” box.

Some more possible functions

  • We already saw how to set adder inputs A, B and CI to compute either X + Y or X - Y.
  • How can we produce the increment function G = X + 1?
  • How about decrement: G = X - 1?
  • How about transfer: G = X? (This can be useful.)

This is almost the same as the increment function!

One way: Set A = 0000 , B = X, and CI = 1

A = 1 1 1 1 (- 1 ), B = X, CI = 0

A = 0000 , B = X, CI = 0

Table of arithmetic functions

  • Here are some of the different possible arithmetic operations.
  • We’ll need some way to specify which function we’re interested in, so

we’ve r andomly assigned a selection code to each operation.

G

Mapping the table to an adder

  • This second table shows what the adder’s inputs should be for each of our eight desired arithmetic operations. - Adder input CI is always the same as selection code bit S 0. - B is always set to X. - A depends only on S 2 and S 1.
  • These equations depend on both the desired operations and the assignment of selection codes.

Selection code Desired arithmetic operation Required adder inputs S 2 S 1 S 0 G (A + B + CI) A B CI 0 0 0 X (transfer) 0000 X 0 0 0 1 X + 1 (increment) 0000 X 1 0 1 0 X + Y (add) Y X 0 0 1 1 X + Y + 1 Y X 1 1 0 0 X + Y’ (1C subtraction) Y’ X 0 1 0 1 X + Y’ + 1 (2C subtraction) Y’ X 1 1 1 0 X – 1 (decrement) 1111 X 0 1 1 1 X (transfer) 1111 X 1

Primitive gate-based input logic

  • We could build this circuit using primitive gates.
  • If we want to use K-maps for simplification, then we should first expand out the abbreviated truth table. - The Y that appears in the output column (A) is actually an input. - We make that explicit in the table on the right.
  • Remember A and Y are each 4 bits long!

S 2 S 1 A 0 0 0000 0 1 Y 1 0 Y’ 1 1 1111

S 2 S 1 Yi Ai 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1

inputs (^) output

Primitive gate implementation

  • From the truth table, we can find an MSP:
  • Again, we have to repeat this once for each bit Y3-Y0, connecting to the adder inputs A3-A0.
  • This completes our arithmetic unit.

S 1 0 0 1 0 S 2 1 0 1 1 Yi

A (^) i = S 2 Yi’ + S 1 Yi

Bitwise operations

  • Most computers also support logical operations like AND, OR and NOT, but extended to multi-bit words instead of just single bits.
  • To apply a logical operation to two words X and Y, apply the operation on each pair of bits X (^) i and Y (^) i :
  • We’ve already seen this informally in two’s-complement arithmetic, when we talked about “complementing” all the bits in a number.

1 0 1 1 AND 1 1 1 0 1 0 1 0

1 0 1 1 OR 1 1 1 0 1 1 1 1

1 0 1 1 XOR 1 1 1 0 0 1 0 1

Defining a logic unit

  • A logic unit supports different logical functions on two multi-bit inputs X and Y, producing an output G.
  • This abbreviated table shows four possible functions and assigns a selection code S to each.
  • We’ll just use multiplexers and some primitive gates to implement this.
  • Again, we need one multiplexer for each

bit of X and Y.

S 1 S 0 Output 0 0 Gi = XiYi 0 1 Gi = Xi + Yi 1 0 Gi = Xi ⊕ Yi 1 1 Gi = Xi’

Our simple logic unit

  • Inputs:
    • X (4 bits)
    • Y (4 bits)
    • S (2 bits)
  • Outputs:
    • G (4 bits)