SlideShare a Scribd company logo
1 of 47
COMPUTER
ARCHITECTURE AND
ORGANIZATION
(CSEG3202 )
Chapter 2:
Computer Arithmetic
Arithmetic & Logic Unit
Computer Architecture and Organization
2
• Does the calculations
• Everything else in the computer is there to
service this unit
• Handles integers
• May handle floating point (real) numbers
ALU Inputs and Outputs
Computer Architecture and Organization
3
Integer Representation
Computer Architecture and Organization
4
 Only have 0 & 1 to represent everything
 Positive numbers stored in binary
 e.g. 41=00101001
 No minus sign
 No period
 Sign-Magnitude
 Two’s compliment
Sign-Magnitude Representation
Computer Architecture and Organization
5
 Left most bit is sign bit
 0 means positive
 1 means negative
 +18 = 00010010
 -18 = 10010010
 Problems
 Need to consider both sign and magnitude in arithmetic
 Two representations of zero (+0 and -0)
Twos Complement Representation
Computer Architecture and Organization
6
 Like sign magnitude, twos complement
representation uses the most significant bit as a sign
bit,
 Easy to test whether an integer is positive or
negative.
 Differs from the use of the sign-magnitude
representation in the way that the other bits are
interpreted
 +3 = 00000011
 +2 = 00000010
 +1 = 00000001
Benefits
Computer Architecture and Organization
7
• One representation of zero
• Arithmetic works easily (see later)
• Negating is fairly easy
—3 = 00000011
—Boolean complement gives 11111100
—Add 1 to LSB 11111101
Negation Special Case 1
Computer Architecture and Organization
8
 0 = 00000000
 Bitwise not 11111111
 Add 1 to LSB +1
 Result 1 00000000
 Overflow is ignored, so:
 - 0 = 0 
Negation Special Case 2
Computer Architecture and Organization
9
 -128 = 10000000
 bitwise not 01111111
 Add 1 to LSB +1
 Result 10000000
 So:
 -(-128) = -128 X
 Monitor MSB (sign bit)
 It should change during negation
Main Features
Computer Architecture and Organization
10
Range of Numbers
Computer Architecture and Organization
11
• 8 bit 2s compliment
—+127 = 01111111 = 27 -1
— -128 = 10000000 = -27
• 16 bit 2s compliment
—+32767 = 011111111 11111111 = 215 - 1
— -32768 = 100000000 00000000 = -215
Conversion Between Lengths
Computer Architecture and Organization
12
• Positive number pack with leading zeros
• +18 = 00010010
• +18 = 00000000 00010010
• Negative numbers pack with leading ones
• -18 = 11101110
• -18 = 11111111 11101110
• i.e. pack with MSB (sign bit)
Addition and Subtraction
Computer Architecture and Organization
13
• Normal binary addition
• Monitor sign bit for overflow
• Take twos compliment of substahend and
add to minuend
—i.e. a - b = a + (-b)
• So we only need addition and complement
circuits
Addition and Overflow rule
Computer Architecture and Organization
14
If two numbers are added, and they are both positive or both negative,
then overflow occurs if and only if the result has the opposite sign.
Subtraction and overflow
Computer Architecture and Organization
15
Hardware for Addition and
Subtraction
Computer Architecture and Organization
16
Multiplication
Computer Architecture and Organization
17
• Complex
• Work out partial product for each digit
• Take care with place value (column)
• Add partial products
Unsigned Multiplication of Example
Computer Architecture and Organization
18
M – multiplicand Q – multiplier C –Carry A – Partial Accumulator
Unsigned Binary Multiplication
Computer Architecture and Organization
19
Multiplying negative numbers
Computer Architecture and Organization
20
Multiplying Negative Numbers
Computer Architecture and Organization
21
 This does not work!
 Solution 1
 Convert to positive if required
 Multiply as above
 If signs were different, negate answer
 Solution 2
 Booth’s algorithm
Booth’s Algorithm
Computer Architecture and Organization
22
Example of Booth’s Algorithm
Computer Architecture and Organization
23
Division
Computer Architecture and Organization
24
 More complex than multiplication
 Negative numbers are really bad!
Division of Unsigned Binary Integers
Computer Architecture and Organization
25
001111
1011
00001101
10010011
1011
001110
1011
1011
100
Quotient
Dividend
Remainder
Partial
Remainders
Divisor
Flowchart for Unsigned Binary
Division
Computer Architecture and Organization
26
Division
Computer Architecture and Organization
27
Twos complement division
Computer Architecture and Organization
28
1. Load the divisor into the M register and the dividend into the A,Q
registers.
2. Shift A,Q left one position.
3. If M and A have the same signs, perform A-M else perform A+M
4. The preceding operation is successful if the sign of A is the same as
before, after the operation,
* if the operation is successful or A = 0, then set Q0 = 1
* if the operation is unsuccessful and A is = not 0 then set Q0 = 0
and restore the previous value of A.
5. Repeat steps 2 through 4 as many times as there are bit positions in
Q.
6. The remainder is in A. If the signs of the divisor and dividend is
the same, then the quotient is Q, else it is the twos complement of
Q.
Is this correct?
Computer Architecture and Organization
29
D = Q X V + R -7 = -2 X 3 - 1
where
D = dividend - 1001 (-7)
Q = quotient – the twos complement of 1110(-2)
V = divisor – 0011 (3)
R = remainder – 1111 (-1)
D = 1110 X 0011+ 1111
= 1001
Signed Division
Computer Architecture and Organization
30
Real Numbers
Computer Architecture and Organization
31
 Numbers with fractions
 Could be done in pure binary
 1001.1010 = 24 + 20 +2-1 + 2-3 =9.625
 Where is the binary point?
 Fixed?
 Very limited
 Moving?
 How do you show where it is?
Floating Point
Computer Architecture and Organization
32
 +/- .significand x 2exponent
 Point is actually fixed between sign bit and body of
mantissa
 Exponent indicates place value (point position)
Floating Point Examples
Computer Architecture and Organization
33
Signs for Floating Point
Computer Architecture and Organization
34
 Exponent is in excess or biased notation
 e.g. Excess (bias) 127 means
 8 bit exponent field
 Pure value range 0-255
 Subtract 127 to get correct value
 Range -127 to +128
Normalization
Computer Architecture and Organization
35
 FP numbers are usually normalized
 i.e. exponent is adjusted so that leading bit (MSB) of
mantissa is 1
 Since it is always 1 there is no need to store it
 (c.f. Scientific notation where numbers are normalized to
give a single digit before the decimal point
 e.g. 3.123 x 103)
Accuracy
Computer Architecture and Organization
36
 Accuracy
 The effect of changing lsb of mantissa
 23 bit mantissa 2-23  1.2 x 10-7
 About 6 decimal places
 Maximum Value is determined by the exponent
Expressible Numbers
Computer Architecture and Organization
37
Signs for Floating Point
Computer Architecture and Organization
38
 Exponent is in excess or biased notation
 e.g. Excess (bias) 127 means
 8 bit exponent field
 Pure value range 0-255
 Subtract 127 to get correct value
 Range -127 to +128
Density of Floating Point Numbers
Computer Architecture and Organization
39
IEEE 754
Computer Architecture and Organization
40
 Standard for floating point storage
 32 and 64 bit standards
 8 and 11 bit exponent respectively
 Extended formats (both mantissa and exponent) for
intermediate results
IEEE 754 Formats
Computer Architecture and Organization
41
FP Arithmetic +/-
Computer Architecture and Organization
42
 Check for zeros
 Align significands (adjusting exponents)
 Add or subtract significands
 Normalize result
FP Addition & Subtraction Flowchart
Computer Architecture and Organization
43
FP Arithmetic x/
Computer Architecture and Organization
44
 Check for zero
 Add/subtract exponents
 Multiply/divide significands (watch sign)
 Normalize
 Round
 All intermediate results should be in double length
storage
Floating Point Multiplication
Computer Architecture and Organization
45
Floating Point Division
Computer Architecture and Organization
46
COMPUTER
ARCHITECTURE AND
ORGANIZATION
(CSEG3202 )
End of Chapter 2

More Related Content

Similar to 2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx

Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...mayurjagdale4
 
Arithmetic Operations
Arithmetic OperationsArithmetic Operations
Arithmetic Operationsgueste99d9a
 
Arithmetic Process in Computer Systems
Arithmetic Process in Computer SystemsArithmetic Process in Computer Systems
Arithmetic Process in Computer SystemsS N M P Simamora
 
Data representation moris mano ch 03
Data representation   moris mano ch  03Data representation   moris mano ch  03
Data representation moris mano ch 03thearticlenow
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmeticSanjay Saluth
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptskatiarrahaman
 
digital systems and information
digital systems and informationdigital systems and information
digital systems and informationKamran Zafar
 
100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).ppt100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).pptnamraashraf56
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1Deepak John
 
Computer arithmetics (computer organisation & arithmetics) ppt
Computer arithmetics (computer organisation & arithmetics) pptComputer arithmetics (computer organisation & arithmetics) ppt
Computer arithmetics (computer organisation & arithmetics) pptSuryaKumarSahani
 
Digital fundamendals r001a
Digital fundamendals r001aDigital fundamendals r001a
Digital fundamendals r001aarunachalamr16
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2Umang Gupta
 
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcBOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcAbhishek Rajpoot
 
2sComplementArithmetic1.ppt
2sComplementArithmetic1.ppt2sComplementArithmetic1.ppt
2sComplementArithmetic1.pptSathishkumar.V
 

Similar to 2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx (20)

Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...
 
09 arithmetic
09 arithmetic09 arithmetic
09 arithmetic
 
Arithmetic Operations
Arithmetic OperationsArithmetic Operations
Arithmetic Operations
 
Arithmetic Process in Computer Systems
Arithmetic Process in Computer SystemsArithmetic Process in Computer Systems
Arithmetic Process in Computer Systems
 
Datarepresentation2
Datarepresentation2Datarepresentation2
Datarepresentation2
 
Data representation moris mano ch 03
Data representation   moris mano ch  03Data representation   moris mano ch  03
Data representation moris mano ch 03
 
Okkkkk
OkkkkkOkkkkk
Okkkkk
 
Number_Systems (2).ppt
Number_Systems (2).pptNumber_Systems (2).ppt
Number_Systems (2).ppt
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmetic
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.ppt
 
digital systems and information
digital systems and informationdigital systems and information
digital systems and information
 
100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).ppt100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).ppt
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1
 
Computer arithmetics (computer organisation & arithmetics) ppt
Computer arithmetics (computer organisation & arithmetics) pptComputer arithmetics (computer organisation & arithmetics) ppt
Computer arithmetics (computer organisation & arithmetics) ppt
 
Digital fundamendals r001a
Digital fundamendals r001aDigital fundamendals r001a
Digital fundamendals r001a
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcBOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
 
2sComplementArithmetic1.ppt
2sComplementArithmetic1.ppt2sComplementArithmetic1.ppt
2sComplementArithmetic1.ppt
 

Recently uploaded

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx

  • 2. Arithmetic & Logic Unit Computer Architecture and Organization 2 • Does the calculations • Everything else in the computer is there to service this unit • Handles integers • May handle floating point (real) numbers
  • 3. ALU Inputs and Outputs Computer Architecture and Organization 3
  • 4. Integer Representation Computer Architecture and Organization 4  Only have 0 & 1 to represent everything  Positive numbers stored in binary  e.g. 41=00101001  No minus sign  No period  Sign-Magnitude  Two’s compliment
  • 5. Sign-Magnitude Representation Computer Architecture and Organization 5  Left most bit is sign bit  0 means positive  1 means negative  +18 = 00010010  -18 = 10010010  Problems  Need to consider both sign and magnitude in arithmetic  Two representations of zero (+0 and -0)
  • 6. Twos Complement Representation Computer Architecture and Organization 6  Like sign magnitude, twos complement representation uses the most significant bit as a sign bit,  Easy to test whether an integer is positive or negative.  Differs from the use of the sign-magnitude representation in the way that the other bits are interpreted  +3 = 00000011  +2 = 00000010  +1 = 00000001
  • 7. Benefits Computer Architecture and Organization 7 • One representation of zero • Arithmetic works easily (see later) • Negating is fairly easy —3 = 00000011 —Boolean complement gives 11111100 —Add 1 to LSB 11111101
  • 8. Negation Special Case 1 Computer Architecture and Organization 8  0 = 00000000  Bitwise not 11111111  Add 1 to LSB +1  Result 1 00000000  Overflow is ignored, so:  - 0 = 0 
  • 9. Negation Special Case 2 Computer Architecture and Organization 9  -128 = 10000000  bitwise not 01111111  Add 1 to LSB +1  Result 10000000  So:  -(-128) = -128 X  Monitor MSB (sign bit)  It should change during negation
  • 10. Main Features Computer Architecture and Organization 10
  • 11. Range of Numbers Computer Architecture and Organization 11 • 8 bit 2s compliment —+127 = 01111111 = 27 -1 — -128 = 10000000 = -27 • 16 bit 2s compliment —+32767 = 011111111 11111111 = 215 - 1 — -32768 = 100000000 00000000 = -215
  • 12. Conversion Between Lengths Computer Architecture and Organization 12 • Positive number pack with leading zeros • +18 = 00010010 • +18 = 00000000 00010010 • Negative numbers pack with leading ones • -18 = 11101110 • -18 = 11111111 11101110 • i.e. pack with MSB (sign bit)
  • 13. Addition and Subtraction Computer Architecture and Organization 13 • Normal binary addition • Monitor sign bit for overflow • Take twos compliment of substahend and add to minuend —i.e. a - b = a + (-b) • So we only need addition and complement circuits
  • 14. Addition and Overflow rule Computer Architecture and Organization 14 If two numbers are added, and they are both positive or both negative, then overflow occurs if and only if the result has the opposite sign.
  • 15. Subtraction and overflow Computer Architecture and Organization 15
  • 16. Hardware for Addition and Subtraction Computer Architecture and Organization 16
  • 17. Multiplication Computer Architecture and Organization 17 • Complex • Work out partial product for each digit • Take care with place value (column) • Add partial products
  • 18. Unsigned Multiplication of Example Computer Architecture and Organization 18 M – multiplicand Q – multiplier C –Carry A – Partial Accumulator
  • 19. Unsigned Binary Multiplication Computer Architecture and Organization 19
  • 20. Multiplying negative numbers Computer Architecture and Organization 20
  • 21. Multiplying Negative Numbers Computer Architecture and Organization 21  This does not work!  Solution 1  Convert to positive if required  Multiply as above  If signs were different, negate answer  Solution 2  Booth’s algorithm
  • 23. Example of Booth’s Algorithm Computer Architecture and Organization 23
  • 24. Division Computer Architecture and Organization 24  More complex than multiplication  Negative numbers are really bad!
  • 25. Division of Unsigned Binary Integers Computer Architecture and Organization 25 001111 1011 00001101 10010011 1011 001110 1011 1011 100 Quotient Dividend Remainder Partial Remainders Divisor
  • 26. Flowchart for Unsigned Binary Division Computer Architecture and Organization 26
  • 28. Twos complement division Computer Architecture and Organization 28 1. Load the divisor into the M register and the dividend into the A,Q registers. 2. Shift A,Q left one position. 3. If M and A have the same signs, perform A-M else perform A+M 4. The preceding operation is successful if the sign of A is the same as before, after the operation, * if the operation is successful or A = 0, then set Q0 = 1 * if the operation is unsuccessful and A is = not 0 then set Q0 = 0 and restore the previous value of A. 5. Repeat steps 2 through 4 as many times as there are bit positions in Q. 6. The remainder is in A. If the signs of the divisor and dividend is the same, then the quotient is Q, else it is the twos complement of Q.
  • 29. Is this correct? Computer Architecture and Organization 29 D = Q X V + R -7 = -2 X 3 - 1 where D = dividend - 1001 (-7) Q = quotient – the twos complement of 1110(-2) V = divisor – 0011 (3) R = remainder – 1111 (-1) D = 1110 X 0011+ 1111 = 1001
  • 31. Real Numbers Computer Architecture and Organization 31  Numbers with fractions  Could be done in pure binary  1001.1010 = 24 + 20 +2-1 + 2-3 =9.625  Where is the binary point?  Fixed?  Very limited  Moving?  How do you show where it is?
  • 32. Floating Point Computer Architecture and Organization 32  +/- .significand x 2exponent  Point is actually fixed between sign bit and body of mantissa  Exponent indicates place value (point position)
  • 33. Floating Point Examples Computer Architecture and Organization 33
  • 34. Signs for Floating Point Computer Architecture and Organization 34  Exponent is in excess or biased notation  e.g. Excess (bias) 127 means  8 bit exponent field  Pure value range 0-255  Subtract 127 to get correct value  Range -127 to +128
  • 35. Normalization Computer Architecture and Organization 35  FP numbers are usually normalized  i.e. exponent is adjusted so that leading bit (MSB) of mantissa is 1  Since it is always 1 there is no need to store it  (c.f. Scientific notation where numbers are normalized to give a single digit before the decimal point  e.g. 3.123 x 103)
  • 36. Accuracy Computer Architecture and Organization 36  Accuracy  The effect of changing lsb of mantissa  23 bit mantissa 2-23  1.2 x 10-7  About 6 decimal places  Maximum Value is determined by the exponent
  • 38. Signs for Floating Point Computer Architecture and Organization 38  Exponent is in excess or biased notation  e.g. Excess (bias) 127 means  8 bit exponent field  Pure value range 0-255  Subtract 127 to get correct value  Range -127 to +128
  • 39. Density of Floating Point Numbers Computer Architecture and Organization 39
  • 40. IEEE 754 Computer Architecture and Organization 40  Standard for floating point storage  32 and 64 bit standards  8 and 11 bit exponent respectively  Extended formats (both mantissa and exponent) for intermediate results
  • 41. IEEE 754 Formats Computer Architecture and Organization 41
  • 42. FP Arithmetic +/- Computer Architecture and Organization 42  Check for zeros  Align significands (adjusting exponents)  Add or subtract significands  Normalize result
  • 43. FP Addition & Subtraction Flowchart Computer Architecture and Organization 43
  • 44. FP Arithmetic x/ Computer Architecture and Organization 44  Check for zero  Add/subtract exponents  Multiply/divide significands (watch sign)  Normalize  Round  All intermediate results should be in double length storage
  • 45. Floating Point Multiplication Computer Architecture and Organization 45
  • 46. Floating Point Division Computer Architecture and Organization 46