IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of...

19
IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education

Transcript of IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of...

Page 1: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

IT253: Computer Organization

Lecture 8:Computer Arithmetic:

Making a Processor

Tonga Institute of Higher Education

Page 2: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Computer Arithmetic

• The next step after designing basic circuits is to create more complicated circuits that will lead us to our CPU

• We will look at computer arithmetic and an ALU, and then start to look into the processor design.

• An ALU is an Arithmetic-Logic Unit. It is an important part of a processor.

• It does the adding, subtracting and logical operations (AND,OR,NOT) in a computer.

• An "ALU Slice" is an ALU for just 2 bits.

Page 3: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Addition and our 1-bit Adder

Truth Table for AddingGate Implementation of 1-Bit Adder

Page 4: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Full Adder/Ripple Adder

• It is simple to put the full adders together.• With that we can form a ripple adder, or an adder that will add any number of bits.• If we want a 16 bit adder, we just need to put 16 full

adders together.

Page 5: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

ALU Slice• Now that we have an adder, we can create most of the ALU. • We still need to do subtracting, but we can make an ALU

Slice. • This will do logic operations and adding

Page 6: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Subtracting and our New ALU Slice

• For a more complete ALU we need to put in subtracting. • There is an easy way to do this. • We just need to realize we are using 2's complement• Then we just invert the second number

• To do this we add an extra input. •Binv will choose to subtract (by inverting B) if Binv is 1. • If it is zero, then it does not change anything and the operation stays as an add.• When we need to add +1 (because it’s 2’s complement)we just set Cin=1 for first bit

Page 7: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Overflow• All we need now is a way to detect overflow

and we will have a full ALU. • We don’t need to stop it, but we need a way

to tell the computer that there was overflow, so that the computer can do the right thing.

• To see if there is overflow, we can take the XOR of the carry in and the carry out of the last bit.

• If they are not the same, then there is overflow

Page 8: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

OverflowIf we take the XOR of the carry in and the carry out of the last bit, we can see if there is overflow.

Page 9: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

The Whole ALU• Remember the ripple adder where we put full

adders together. If we wanted to add 16 bits, we would put 16 full adders together.

• The same works with the ALU. To make a full ALU, put together 32 of them and you can use 32 bit numbers (means you can add, subtract, AND,OR,NOT with 32 bit numbers)

Page 10: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Making a smaller ALU

• We need an easy way to draw the ALU,

• Just like the full adder, we will make a little box

Page 11: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Integer Multiplication

• We’ve done adding, subtracting, AND,OR. We also need a way to multiply numbers.

• Example– Product = Multiplicand * Multiplier

Multiplicand 101Multiplier x 110 000 1010 + 10100Product 11110

Page 12: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Multiplication

• What we need is an algorithm (a series of steps) that can do a multiplication operation. – Algorithm:

• If multiplier digit is 1, add a shifted copy of multiplicand to product

• If multiplier digit is 0, add zero to product

– This means for a 32 bit number, it will take 32 steps to multiply a number

Page 13: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Multiplication HardwareThe Multiplicand will keep getting shifted over. It has to be 64 bits. The Product will also be 64 bits. Multiplier only needs 32 bits

Page 14: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Multiplication and Division• This algorithm is a simple and very inefficient (slow)

algorithm. • There are better algorithms, but they are complicated• Division will use the same hardware as multiplication, we

will just change a few simple things• With division we will shift the remainder left, inside of the

divisor right

Divisor Hardware

Page 15: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Floating Point Addition• We have seen how to add, subtract, multiply and divide

whole integers, but what about numbers with decimals?• The algorithm for floating point addition:

– Example: 1.610 x 10-1 + 9.999 x 102

– Step 1: Align decimal points• 0.016 x 101 +99.99 x 101

– Step 2: Add together • 0.016 x 101 +99.99 x 101 = 100.015 x 101

– Step 3: Normalize• 100.015 x 101 = 1.00015 x 103

– Step 4: Round (because we only have so many mantissa spots)

• Example (to show rounding)

• 1.00015 x 103 = 1.0002 x 103

Page 16: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Floating Point HardwareHardware will do all

the steps of the algorithm.

1. Align numbers2. Add3. Normalize4. Round

Sometimes you may need to normalize and round more than once to get the level of accuracy that your hardware can support. (For example, if you have a 32 bit number, it will be less accurate than 64 bits)

Page 17: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Problems with Floating Points

• Accuracy is a big issue with floating points. • For example, is (x + y) + z = x + (y + z)

– the first operation, inside the parentheses, may round the number so that it is a different result

• Computers only have a limited size (mostly 32 bits), so you can only have numbers that are accurate to a limited point

Page 18: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Exceptions

• Exceptions are errors that the computer hardware will notify the user about.

• There are a few exceptions we need to make sure the computer knows about– Overflows, underflows and division by zero– Square root of -1, infinity.

• These are examples of things we would have to consider when making hardware

Page 19: IT253: Computer Organization Lecture 8: Computer Arithmetic: Making a Processor Tonga Institute of Higher Education.

Summary

• We looked at how to implement a full ALU and make it work with 32 bit numbers.

• We also looked at some other elements we need on a processor.

• We tried to make hardware to do multiplication and division.

• We also looked at what we would need for floating point numbers

• Next time: Designing our processor