14
Computer Science 210 Computer Organization The Arithmetic Logic Unit

Computer Science 210 Computer Organization The Arithmetic Logic Unit

Embed Size (px)

Citation preview

Page 1: Computer Science 210 Computer Organization The Arithmetic Logic Unit

Computer Science 210Computer Organization

The

Arithmetic Logic Unit

Page 2: Computer Science 210 Computer Organization The Arithmetic Logic Unit

ALU - General

• Goal is to design simple ALU

• Actually there are relatively few basic arithmetic logic operations needed

• Many instructions can be implemented in terms of the basic ones

Page 3: Computer Science 210 Computer Organization The Arithmetic Logic Unit

ALU Building Blocks

AND GateNOT Gate

OR Gate Multiplexor

Page 4: Computer Science 210 Computer Organization The Arithmetic Logic Unit

• Let's build an ALU to support the andi and ori instructions– we'll just build a 1 bit ALU, and use 32 of them

An ALU (arithmetic logic unit)

ba

operation

result

Page 5: Computer Science 210 Computer Organization The Arithmetic Logic Unit

• Selects one of the inputs to be the output, based on a control input

• We’ll use a MUX for our ALU

Review: The Multiplexer

0

1

S

CA

B

Page 6: Computer Science 210 Computer Organization The Arithmetic Logic Unit

1-Bit Logical Unit

0

1

0 - AndOperation 1 - Or

Result

Operation

Page 7: Computer Science 210 Computer Organization The Arithmetic Logic Unit

1-Bit ALU with Addition

b

0

2

R e su lt

O pe ra t io n

a

1

C a rry In

C a rryO u t

Page 8: Computer Science 210 Computer Organization The Arithmetic Logic Unit

32 bit ALU

b

0

2

Result

Operation

a

1

CarryIn

CarryOut

Result31a31

b31

Result0

CarryIn

a0

b0

Result1a1

b1

Result2a2

b2

Operation

ALU0

CarryIn

CarryOut

ALU1

CarryIn

CarryOut

ALU2

CarryIn

CarryOut

ALU31

CarryIn

Page 9: Computer Science 210 Computer Organization The Arithmetic Logic Unit

• Two's complement approach: just negate b and add one.

• How do we negate?

What about subtraction (a – b) ?

0

2

Result

Operation

a

1

CarryIn

CarryOut

0

1

Binvert

b

Page 10: Computer Science 210 Computer Organization The Arithmetic Logic Unit

32 bit ALU

Result31a31

b31

Result0

CarryIn

a0

b0

Result1a1

b1

Result2a2

b2

Operation

ALU0

CarryIn

CarryOut

ALU1

CarryIn

CarryOut

ALU2

CarryIn

CarryOut

ALU31

CarryIn

0

2

Result

Operation

a

1

CarryIn

CarryOut

0

1

b

binvert

binvert = 1, carryin = 1, operation = 2, gives a + ~b + 1 = a - b

binvert

+

Page 11: Computer Science 210 Computer Organization The Arithmetic Logic Unit

Overflow Detection

Operation Operand A Operand B Result

+ 0 0 < 0

+ < 0 < 0 0

- 0 < 0 < 0

- < 0 0 0

Note: This can be determined by what happens in the high order bit.

Page 12: Computer Science 210 Computer Organization The Arithmetic Logic Unit

Overflow Detection

Operation A’s High Bit B’s High Bit ResultHigh Bit

+ 0 0 1

+ 1 1 0

- 0 1 1

- 1 0 0

Note: If we used the output of the binvert MUX, the rows for subtraction would be the same as for addition.

Page 13: Computer Science 210 Computer Organization The Arithmetic Logic Unit

Overflow Detection

A’s High Bit

Binvert MUX ResultHigh Bit

Overflow

0 0 1 1

1 1 0 1

Note: The other rows of a truth table for Overflow wouldbe 0. So, we could build an overflow detector with

_ _ _AMR + AMR

Page 14: Computer Science 210 Computer Organization The Arithmetic Logic Unit

High Order 1-Bit ALU(with overflow hardware)

0

2

Resu lt

O peration

a

1

Carry In

CarryOut

0

1

B inve rt

b

Overflow