Professional Documents
Culture Documents
BBT 2103: Computer Organization
BBT 2103: Computer Organization
Overview
In this lecture, we focus on the ALU and its operation
Overview of the ALU itself Data representation (review!) Computer Arithmetic and its H/W implementation
The ALU
ALU performs arithmetic and logical operations on data All other system elements are there (mainly) to bring data to the ALU for processing or to take results from the ALU In early machines, simplicity and reliability determined the overall structure of the CPU and its ALU
Result was machines built around a single register, the accumulator
Today general registers can be used as sources and destinations for many ALU operations
3
Number Representation
Any number can be represented in any base by the simple sum of each digit's value, positional notation: d * basei Examples
The value 294 in decimal (29410) equals 2 * 102 + 9 * 101 + 4 * 100 The value 1011 (binary) equals 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20 ( 11 in decimal).
As a 16 bit number this would be represented as follows:
With 16 bits it is possible to have unsigned numbers that range from 0 to 216 - 1 = 65535.
4
Signed Integers
It is highly useful to be able to represent negative as well as positive integers. Several representation methods are possible:
Sign-magnitude format Ones Complement Format Twos Complement format
Signed-magnitude format
Positional representation using n bits Left most bit (MSB) position is the sign bit, which can be
0 for positive number 1 for negative number
Remaining n-1 bits represent the magnitude Range of numbers that can be represented is: {-2n-1-1, +2n-1-1} Problems:
Sign must be considered during arithmetic operations Has a dual representation of zero (-0 and +0)
6
This representation still suffers from the problem of dual representation of Zero
7
All negative numbers have 1 in the most significant bit position, making sign detection very simple
8
Exercise: Convert the following decimal numbers into to two's complement binary 42, -70 9
Example: Convert from 8 to 16 bits +18 = 00010010 +18 = 00000000 00010010 -18 = 11101110 -18 = 11111111 11101110
10
Overflow
An overflow can occur whenever the sum of two N bit numbers cannot be represented by another N bit number To detect an overflow the following rule is observed
If both the operands are positive or negative, and the result is of the opposite sign, then overflow occurs
Hardware implementation
A single full adder is the simplest hardware
Must implement an n-repetition for-loop for an nbit addition This is lots of overhead for a typical addition
Circuit Diagram
13
14
15
16
Integer Subtraction
Subtraction uses addition: The appropriate operand is negated before being added The following illustrates this (a) Direct subtraction 0000 0111 7 - 0000 0110 - 6 0000 0001 =1 (b) Using Twos Complement 0000 0111 7 + 1111 1010 +-6 0000 0001 =1
17
Adder-Subtractor Hardware
The general hardware to accomplish addition and subtraction is shown below
18
Multiplication Example
Example: using paper and pen perform 11 * 13
1011 x 1101 1011 00000 101100 1011000 10001111 (11) (13)
(143)
19
Integer Multiplication
A number of methods exist for the implementation of multiplication
Repeated addition Shift and add High speed (special purpose) hardware multipliers
Repeated addition
Least sophisticated method Just use adder over and over again If the multiplier is n bits, can have as many as 2n iterations of addition Not used in an ALU
20
21
Multiplication Implementation
A possible hardware implementation is shown below
22
Multiplication Flowchart
23
Execution Example
24
Convert numbers to positive magnitudes, multiple, then figure out the correct sign Or use a method that works for both positive and negative numbers
E.g Booths Algorithm
25
Booths Algorithm
As in S&A, strings of 0s in the multiplier only require shifting (no addition steps) In other words
At the right end of a string of 1s in the multiplier (10), perform a subtraction At the left end of the string perform an addition (01) For all of the 1s in between, just do shifts
To determine operation (add and shift, subtract and shift, shift) examine the bits Q0Q-1
00 or 11: just shift 10: subtract and shift 01: add and shift
26
Booths Algorithm
27
28
29
30
Integer Division
Once you have committed to implementing multiplication, implementing division is a relatively easy next step that utilizes much of the same hardware The goal is to find a quotient, Q, and remainder, R, such that
D=QxV+R
31
32
Restore Division
Adapted from pen and paper approach Uses essentially the same ALU hardware as the Booth multiplication algorithm
33
34
35
Requires the ability to dynamically move the decimal point to a convenient location
Similar to scientific notation: 3.14159 x 1023
37
Range vs Precision
For a fixed n-bit representation length, there are 2n combinations of symbols If floating point increases the range of numbers in the format (compared to integer representation) then the spacing between the numbers must increase
This causes a decrease in the formats precision
If more bits are allocated to the exponent, range is increased at the expense of decreased precision Similarly, more mantissa bits increases the precision and reduces the range
39
Example
For a 32 bit number
8 bit exponent
+/-2256 1.5 x 1077
40
41
42
Double precision
Range 10-308 to 10+308 11-bit exponent with 1023 bias 52-bit mantissa
43
FP Arithmetic
Addition and subtraction
First, align decimal points Then, add or subtract mantissas Finally, normalize result
Example
9.997 x 102 4.631 x 10-1 Sum Normalized 9.997000 x 102 0.004631 x 102 10.001631 x 102 1.0001631 x 103
44
FP Arithmetic
Multiplication
Add exponents Multiply mantissas Post normalize
Division
Subtract exponents Divide mantissas Post normalize
45
Summary
Looked at the basic concepts associated with computer arithmetic
Number representation Basic ALU construction Hardware and software algorithms Floating point numbers and arithmetic
46