2. is the final processing performed by the processor
3. after the information has been processed by the ALU, it is sent to the computer memory
4. a combinational circuits that performs arithmetic and logical operations
5. arithmetic operations include addition,subtraction,multiplication,division,ect
6. logical operations involve Boolean logic :AND,OR,NOT and XOR
6. a fundamental component of all processors
7. the design and function of an ALU may vary between different processor models
8. for example, some ALUs only perform integer calculations, while others are designed to handle floating point operations as well
ALU Input and Output
1. Data are presented to the ALU in registers, and the results of an operation are stored in registers.
2. These registers are
temporary storage locations within the processor that are connected by signal
paths to the ALU.
3. The ALU may also set flags
as the result of an operation.
4. For example, an overflow
flag is set to 1 if the result of a computation exceeds the length of the
register into which it is to be stored.
A typical diagram of an ALU
Arithmetic Logic Unit schematic symbol
|
- A and B are the data inputs
- F is the
control input to choose the function
- R is the result of the function applied
to A and B
- D is the status of the output
Example of arithmetic operation :
1. Two's Complement Addition : add the values and discard any carry-out bit.
using 8-bit two’s
complement numbers.
a). Add −8 to +3
(+3)
0000 0011
+(−8) 1111 1000
------------------------
(−5)
1111 1011
b). Add −5 to −2
(−2)
1111 1110
+(−5) 1111 1011
------------------------
(−7) 1 1111 1001 : discard carry-out
2. Overflow Rule for addition :
- If 2 Two's Complement numbers are added, and they both have the same sign (both positive or both
negative), then overflow occurs if and only if the result has the opposite sign. Overflow never occurs when adding operands with different signs.
i.e. | Adding two positive numbers must give a positive result |
Adding two negative numbers must give a negative result |
Overflow occurs if
- (+A) + (+B) = −C
- (−A) + (−B) = +C
Using 4-bit Two's Complement numbers (−8 ≤ x ≤ +7)
(−7) 1001
+(−6) 1010
--------------
(−13) 1 0011 = 3 : Overflow (largest −ve number is −8)
3. Two's Complement Subtraction : Normally accomplished by negating the subtrahend and adding it to the minuhend. Any carry-out is discarded.
Using 8-bit Two's Complement Numbers (−128 ≤ x ≤ +127) (+8) 0000 1000 0000 1000
−(+5) 0000 0101 -> Negate -> +1111 1011
------ -------------
(+3) 1 0000 0011 : discard carry-out
4. Overflow Rule for Subtraction :
- If 2 Two's Complement numbers are subtracted, and their signs are different, then overflow occurs if and only if the result has the same sign as the subtrahend.
Overflow occurs if- (+A) − (−B) = −C
- (−A) − (+B) = +C
Subtract −6 from +7
(+7) 0111 0111
−(−6) 1010 -> Negate -> +0110
------------- -------
13 1101 = −8 + 5 = −3 : Overflow
5. Two's Complement Summary
i). Addition
- Add the values, discarding any carry-out bit
- Negate the subtrahend and add, discarding any carry-out bit
- Occurs when adding two positive numbers produces a negative result, or when adding two negative numbers produces a positive result. Adding operands of unlike signs never produces an overflow
- Notice that discarding the carry out of the most significant bit during Two's Complement addition is a normal occurrence, and does not by itself indicate overflow
- As an example of overflow, consider adding (80 + 80 = 160)10, which produces a result of −9610 in 8-bit two's complement:
01010000 = 80 + 01010000 = 80 ------------- 10100000 = −96 (not 160 because the sign bit is 1.) (largest +ve number in 8 bits is 127)
6. Multiplication and Division
- No problem with unsigned (always positive) numbers, just use the same standard techiques as in base 10 (remembering that x[n] × y[n] = z[2n])- Multiplication Example : 11001012 × 1111012 (10110 × 6110)
1100101 10110 × 111101 × 6110
--------------- 1100101 +1100101
+1100101 +1100101 +1100101 ---------------- ????????????? ----------------
Easier to use intermediary results:
1100101 10110 × 111101 × 6110 ----------- 1100101 +1100101 ------------ 111111001 +1100101 --------------- 10100100001 +1100101 ---------------- 101101110001 +1100101 ----------------- 1100000010001 = 409610 + 204810 + 1610 + 1 = 616110 -----------------
- Division Example : 1001012 ÷ 1012 (3710 ÷ 510)
111 result = 710 ---------
101) 100101 −101 --------- 1000 −101 ------ 111 −101 ------ 10 remainder = 210 ---
Example of logical operations :
1. AND
The logical AND operation compares 2 bits and if they are both "1", then the result is "1", otherwise, the result is "0".
2. OR
The logical OR operation
compares 2 bits and if either or both bits are "1", then the result
is "1", otherwise, the result is "0".
3. XOR
The logical XOR
(Exclusive OR) operation compares 2 bits and if exactly one of them is
"1" (i.e., if they are different values), then the result is
"1"; otherwise (if the bits are the same), the result is
"0".
4. NOT
The logical NOT
operation simply changes the value of a single bit. If it is a "1",
the result is "0"; if it is a "0", the result is
"1". Note that this operation is different in that instead of
comparing two bits, it is acting on a single bit.
No comments:
Post a Comment