Computer Organization & Architecture Unit-2: Arithmetic and Logic Unit

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Computer Organization & Architecture

Unit-2 : Arithmetic and logic unit

Dr. B. K. Sharma
By& Head
Professor
Department of MCA
Ajay Kumar Garg Engineering College, Ghaziabad
Division
• More complex than multiplication
• Negative numbers are really bad!
• Based on long division
Division(cont..)
• The binary division operation is similar to
the base 10 decimal system, except the
base 2.
• The division is probably one of the most
challenging operations of the basic
arithmetic operations.
• There are different ways to solve division
problems using binary operations.
• Long division is one of them and the
easiest and the most efficient way.
Binary Division Rules
• The binary division is much easier than
the decimal division when you remember
the following division rules. The main
rules of the binary division include:
• 1÷1 = 1
• 1÷0 = 0
• 0÷1 = Meaningless
• 0÷0 = Meaningless
Division of Unsigned Binary Integers

00001101 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
001111
1011
100 Remainder
Division of Unsigned Binary Integers
• Given 01111100 ÷ 0010
• Here the dividend is 01111100, and the
divisor is 0010
• Remove the zero’s in the Mos Significant
Bit in both the dividend and divisor, that
doesn’t change the value of the number.
• So the dividend becomes 1111100, and
the divisor becomes 10. Now, use the
long division method.
Division of Unsigned Binary Integers
• Step 1: First, look at the first two numbers in the
dividend and compare with the divisor. Add the
number 1 in the quotient place. Then subtract the
value, you get 1 as remainder.
• Step 2: Then bring down the next number from the
dividend portion and do the step 1 process again
• Step 3: Repeat the process until the remainder
becomes zero by comparing the dividend and the
divisor value.
• Step 4: Now, in this case, after you get the
remainder value as 0, you have zero left in the
dividend portion, so bring that zero to the quotient
portion.
• Therefore, the resultant value is quotient value which
is equal to 111110
• So, 01111100 ÷ 0010 = 111110
Example (4537/3)-Decimal
Example (29/3)- Binary
So Rule is…
Unsigned division

•Division is a more tedious process than multiplication.


•For the unsigned case, there are two standard approaches:
1.) Restoring division. (slow) 2.) Non restoring division (fast).

Graphical illustration of partial


reminder computations in restoring
and non-restoring division
Restoring division

Strategy for unsigned division:


Shift the dividend one bit at a time starting from MSB into a register.
Subtract the divisor from this register.
If the result is negative (“didn’t go”):
- Add the divisor back into the register.
- Record 0 into the result register.
If the result is positive:
- Do not restore the intermediate result.
- Set a 1 into the result register.

Restoring term is due to fact that value of register A is restored after


each iteration.
Restoring division (contd..)

Shift left
Set Register A to 0.
Load dividend in Q.
an an - 1 a0 q
n- 1
q
0 Load divisor into M.
A Dividend Q Repeat n times:
Quotient - Shift A and Q left one
setting
bit.
-Subtract M from A.
n + 1-bit -Place the result in A.
adder Add/Subtract
-If sign of A is 1, set q0 to
Control
sequencer 0 and add M back to A.
Else set q0 to 1.
0 mn - 1 m0
End of the process:
Divisor M
- Quotient will be in Q.
- Remainder will be in A.
Sign bit (result of sub)
Restoring division (contd..)
Restoring division (Flowchart)
Restoring division ( Example-1)
Non-restoring division

Restoring division can be improved using non-restoring algorithm

The effect of restoring algorithm actually is:


If A is positive, we shift it left and subtract M, that is compute 2A-M
If A is negative, we restore it (A+M), shift it left, and subtract M, that
is, 2(A+M) – M = 2A+M.
Set q0 to 1 or 0 appropriately.

Non-restoring algorithm is:


Set A to 0.
Repeat n times:
If the sign of A is positive:
Shift A and Q left and subtract M. Set q0 to
1.
Else if the sign of A is negative:
Shift A and Q left and add M. Set q0 to 0.
If the sign of A is 1, add A to M.
Flowchart
Restoring division (Example-2)

Initially 0 0 0 0 0 1 0 0 0
0 0 0 1 1
Shift 0 0 0 0 1 0 0 0
Subtract 1 1 1 0 1 First cycle
Set q 1 1 1 1 0
0
Restore 1 1
0 0 0 0 1 0 0 0 0
1 0 Shift 0 0 0 1 0 0 0 0
1 1 1 0 0 0 Subtract 1 1 1 0 1
1 1 Set q 1 1 1 1 1 Second cycle
0
Restore 1 1
1 0
0 0 0 1 0 0 0 0 0
Shift 0 0 1 0 0 0 0 0
Subtract 1 1 1 0 1

Set q 0 0 0 0 1 Third cycle


0

Shift 0 0 0 1 0 0 0 0 1
Subtract 1 1 1 0 1 0 0 1

Set q0 1 1 1 1 1
Fourth cycle
Restore 1 1
0 0 0 1 0 0 0 1 0

Remainder Quotient
Initialization
Initialization
Division Example
Thanks!!

You might also like