CS251 - Computer Organization and Design - Spring 2008

Lecture 10 - Addiing and Multiplying Integers


Practical Details

  1. Assignment 1, giving back.
  2. Ignore verilog
  3. One assignment 1 without a name
  4. No class Friday

Integers

Two's complement

Interpret the MSB as -2^31 instead of 2^31. Then,

Negation

  1. Take an arbitrary two's complement number, y,
  2. Make a second two's complement number, x, by inverting all its bits
  3. Add them together
  4. y + x = -1 => -y = x + 1

Sign extension

Put an n-bit number in an n+m-bit slot

  1. Positive:
  2. Negative
  3. Put them together

This is called sign extension


Addition

Truth table for one bit addition

A B | S CO
=========
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1

Extend for carry in

A B CI | S CO
=============
0 0  0 | 0 0
0 0  1 | 1 0
0 1  0 | 1 0
0 1  1 | 0 1
1 0  0 | 1 0
1 0  1 | 0 1
1 1  0 | 0 1
1 1  1 | 1 1

CO = (A XOR B)CI + AB
S = (A XOR B)(NOT CI) + (NOT(A XOR B))CI = (A XOR B) XOR CI

Ripple Adder

One-bit ALU

Use a multiplexor addressed by operation to get the right result

Four-bit ALU


Multiplication

Long multiplication, the algorithm you know and love from grade school

  1. Multiply the right most digit by the multiplicand
  2. Repeat until no more digits
    1. multiply next digit by multiplicant
    2. add one to shifter
    3. shift result left by amount in shifter
    4. add to product

This is hard because multiplying base ten is hard

But we can all multiply by 1 and 0, no problem, so try this algorithm

product is zero

Repeat 32 times

  1. If LSB of multiplier is 1 then
  2. Shift multiplier 1 bit right
  3. Shift multiplicand 1 bit left

Version 2

Shift product register instead of multiplicand register

Version 3

High word of product is zero; low word of product is multiplier

Repeat 32 times

  1. If LSB of product is 1 then
  2. Shift product 1 bit right.
 

Return to: