SlideShare a Scribd company logo
CE

COMPUTER ARCHITECTURE

CHAPTER 3
ARITHMETIC FOR COMPUTERS

1
CE

Arithmetic for Computers

1. Introduction
2. Addition and Subtraction
3. Multiplication
4. Division
5. Floating Point
6. Parallelism and Computer Arithmetic: Associativity

2
CE

Arithmetic for Computers

3
CE

Arithmetic for Computers

1. Introduction
2. Addition and Subtraction
3. Multiplication
4. Division
5. Floating Point
6. Parallelism and Computer Arithmetic: Associativity

4
CE

Introduction

Computer words are composed of bits; thus, words can be represented as
binary numbers. Chapter 2 shows that integers can be represented either in
decimal or binary form, but what about the other numbers that
commonly occur?
For example:
■ What about fractions and other real numbers?

■ What happens if an operation creates a number bigger than can be
represented?
■ And underlying these questions is a mystery: How does hardware

really multiply or divide numbers?

5
CE

Arithmetic for Computers

1. Introduction
2. Addition and Subtraction
3. Multiplication
4. Division
5. Floating Point

6. Parallelism and Computer Arithmetic: Associativity

6
CE

Addition and Subtraction

Addition:

Binary addition, showing carries from right to left

7
CE

Addition and Subtraction

Subtraction:

8
CE

Addition and Subtraction

Overflow
When does the overflow occur on the signed number?

We also need to concern:
- How to detect overflow for two’s complement numbers in a computer?
- What about overflow with unsigned integers? (Unsigned integers are
commonly used for memory addresses where overflows are ignored.)

9
Addition and Subtraction

CE
Overflow

 The computer designer must therefore provide a way to ignore overflow in
some cases and to recognize it in others.

 The MIPS solution is to have two kinds of arithmetic instructions to recognize the two
choices:
■ Add (add), add immediate (addi), and subtract (sub) cause exceptions (interrupt)
on overflow.

■ Add unsigned (addu), add immediate unsigned (addiu), and subtract unsigned
(subu) do not cause exceptions on overflow.

Note: MIPS detects overflow with an exception, also called an interrupt on many
computers. An exception or interrupt is essentially an unscheduled procedure call.
10
CE

Arithmetic for Computers

1. Introduction
2. Addition and Subtraction
3. Multiplication
4. Division
5. Floating Point

6. Parallelism and Computer Arithmetic: Associativity

11
Multiplication

CE
Example

Although the decimal example above happens to use only 0 and 1, multiplication of
binary numbers must always use 0 and 1, and thus always offers only these two choices:
1. Just place a copy of the multiplicand (1 ×multiplicand) in the proper place if the
multiplier digit is a 1.
2. Place 0 (0 ×multiplicand) in the proper place if the multiplier digit is 0.
12
CE

Multiplication

Sequential Version of the Multiplication Algorithm and Hardware

Fig.1: First version of the division hardware

Note: Three steps are repeated 32 times to obtain the
product. If each step took a clock cycle, this algorithm
would require almost 100 clock cycles to multiply two
32-bit numbers.
Fig.2: The first multiplication algorithm 13
CE

Multiplication

Sequential Version of the Multiplication Algorithm and Hardware
Example:

Answer: Step by step follow the multiplication algorithm

14
CE

Multiplication

Sequential Version of the Multiplication Algorithm and Hardware

Fig.3 Refine version of the multiplication hardware

 Compare with the first version in the previous slide, the Multiplicand register, ALU, and
Multiplier register are all 32 bits wide, with only the Product register left at 64 bits.
 It just takes one clock cycle to get the Product.
15
CE

Multiplication

Signed Multiplication
 The easiest way to understand how to deal with signed numbers is to first
convert the multiplier and multiplicand to positive numbers and then
remember the original signs.
 The algorithms should then be run for 31 iterations, leaving the signs out of

the calculation.
 It turns out that the last algorithm will work for signed numbers.

16
CE

Multiplication

Faster Multiplication

Fig.4 Fast multiplication hardware.

17
CE

Multiplication

Multiply in MIPS
 MIPS provides a separate pair of 32-bit registers to contain the 64-bit
product, called Hi and Lo.
 To produce a properly signed or unsigned product, MIPS has two instructions:
multiply (mult) and multiply unsigned (multu).

 To fetch the integer 32-bit product, the programmer uses move from lo (mflo).
The MIPS assembler generates a pseudo instruction for multiply that specifies three
general purpose registers, generating mflo and mfhi instructions to place the product into
registers.

18
CE

Arithmetic for Computers

1. Introduction
2. Addition and Subtraction
3. Multiplication
4. Division
5. Floating Point

6. Parallelism and Computer Arithmetic: Associativity

19
CE

Division

 The reciprocal operation of multiply is divide, an operation that is even less
frequent and even more quirky.
 It even offers the opportunity to perform a mathematically invalid operation:
dividing by 0.
Example:

20
CE

Division

A division algorithm and hardware

Fig.5 First version of the multiplication hardware

Note: both the dividend and the divisor are positive
and hence the quotient and the remainder are
nonnegative. The division operands and both results
are 32-bit values, and we will ignore the sign for now.
Fig.6 The first division algorithm

21
CE

Division

The division algorithm and hardware
Example:

Answer: Step by step follow the multiplication algorithm

22
Division

CE
A faster division hardware

Fig.7 The improved version of the division hardware

23
Division

CE
Signed division

 The simplest solution is to remember the signs of the divisor and dividend and then
negate the quotient if the signs disagree.
 The one complication of signed division is that we must also set the sign of the
remainder. Remember that the following equation must always hold:
Dividend = Quotient x Divisor + Remainder


Remainder = Dividend – (Quotient x Divisor)

Example:

24
CE

Division

Divide in MIPS
 You may have already observed that the same sequential hardware can be used for
both multiply and divide in Fig.3 and Fig.7 .
 The only requirement is a 64-bit register that can shift left or right and a 32-bit ALU
that adds or subtracts. Hence, MIPS uses the 32-bit Hi and 32-bit Lo registers for both
multiply and divide.
 As we might expect from the algorithm above, Hi contains the remainder, and Lo
contains the quotient after the divide instruction completes.
 To handle both signed integers and unsigned integers, MIPS has two instructions:
divide (div) and divide unsigned (divu).

 The MIPS assembler allows divide instructions to specify three registers, generating
the mflo or mfhi instructions to place the desired result into a general-purpose register.
25
CE

Arithmetic for Computers

1. Introduction
2. Addition and Subtraction
3. Multiplication
4. Division
5. Floating Point

6. Parallelism and Computer Arithmetic: Associativity

26
CE

Floating Point

Definitions
Some representations of the real number:

 The alternative notation for the above last two numbers is called scientific
notation, which has a single digit to the left of the decimal point.
 A number in scientific notation that has no leading 0s is called a normalized number
Example: 1.0ten x 10-9: normalized scientific number
0.1ten x 10-8: not normalized scientific number
10.0ten x 10-10: not normalized scientific number

 The binary number shown in scientific notation is called floating point

Floating point: Computer arithmetic that represents numbers in which the binary point is
not fixed.

27
CE

Floating Point

Floating-Point representation
 A designer of a floating-point representation must find a compromise between the size
of the fraction and the size of the exponent.
This tradeoff is between precision and range:
- Increasing the size of the fraction enhances the precision of the fraction.
- Increasing the size of the exponent increases the range of numbers that can be
represented.
 Floating-point numbers are usually a multiple of the size of a word.
The representation of a MIPS floating-point number:

Where
s is the sign of the floating-point number (1 meaning negative)

exponent is the value of the 8-bit exponent field (including the sign of the exponent)
fraction is the 23-bit number

This representation is called sign and magnitude, since the sign is a separate bit from the
rest of the number.
28
In general, floating-point numbers are of the form:
Floating Point

CE
Floating-Point representation

 Overflow (floating-point): A situation in which a positive exponent becomes too large to
fit in the exponent field.
 Underflow (floating-point): A situation in which a negative exponent becomes too large
to fit in the exponent field.
To reduce chances of underflow or overflow is to offer another format that has a larger
exponent. In C this number is called double, and operations on doubles are called double
precision floating-point arithmetic; single precision floating-point is the name of the format
in previous slide.
Double precision: A floating-point value represented in two 32-bit words.
Single precision: A floating-point value represented in a single 32-bit word.

The representation of a double precision floating-point number:

Where: s is the sign of the floating-point number (1 meaning negative)
exponent is the value of the 11-bit exponent field (including the sign of the exponent)
fraction is the 52-bit number

29
CE

Floating Point

Floating-Point representation
 These above formats go beyond MIPS. They are part of the IEEE 754 floating-point
standard (IEEE 754), found in virtually every computer invented since 1980.

 To pack even more bits into the significand (also coefficient or mantissa is part of a
number in scientific notation), IEEE 754 makes the leading 1-bit of normalized binary
numbers implicit. Hence, the number is actually 24 bits long in single precision (implied 1
and a 23-bit fraction), and 53 bits long in double precision (1 +52).
Note: To be precise, we use the term significand to represent the 24- or 53-bit number
that is 1 plus the fraction, and fraction when we mean the 23- or 52-bit number.
 The representation of the rest of the numbers uses the form from before with the hidden 1
added

where the bits of the fraction represent a number between 0 and 1 and E specifies the value
in the exponent field. If we number the bits of the fraction from left to rights1, s2, s3, . . .
,then the value is:
30
CE

Floating Point

Floating-Point representation
 Negative exponents pose a challenge to simplified sorting. If we use two’s complement or
any other notation in which negative exponents have a 1 in the most significant bit of the
exponent field.
Example:
 1.0two x 2-1 would be represented with a negative exponent will look like a big number.

 1.0two x 2+1 would be represented with a negative exponent will look like the smaller
number.

31
CE

Floating Point

Floating-Point representation
 The desirable notation must therefore represent the most negative exponent as 00 . . . 00two
and the most positive as 11 . . . 11two. This convention is called biased notation, with the
bias being the number subtracted from the normal, unsigned representation to determine
the real value.
 IEEE 754 uses a bias of 127 for single precision, so an exponent of -1 is represented by
the bit pattern of the value (-1 + 127ten ), or 126ten = 0111 1110two , and +1 is represented
by (1+127), or 128ten = 1000 0000two .
 The exponent bias for double precision is 1023.

 Importance: Biased exponent means that value represented by a floating-point
number is really:

The range of single precision number is from
as small as
to as large as
Fig.8: IEEE 754 encoding of floating-point numbers

32
CE

Floating Point

Floating-Point representation
Example 1:

33
CE

Floating Point

Floating-Point representation
Answer1:

34
CE

Floating Point

Floating-Point representation
Answer1:

35
CE

Floating Point

Floating-Point representation
Example 2: Converting Binary to Decimal Floating-Point

Answer 2:

36
CE

Floating Point

Floating-Point addition
Let’s add numbers in scientific notation by hand to illustrate the problem in floatingpoint addition: 9.999ten x 101 + 1.610ten x 10-1. Assume that we can store only four

decimal digits of the significand and two decimal digits of the exponent.

37
CE

Floating Point

Floating-Point addition

Note: check for overflow or underflow
 the exponent still fits in its field

38
CE

Floating Point

Floating-Point addition
The algorithm for binary
floating-point addition.

Fig.9 The algorithm for binary
floating-point addition.

39
CE

Floating Point

Floating-Point addition
Example: Try adding the number 0.5ten and -0.4375ten in binary using the algorithm in Fig.9
Answer:

40
CE

Floating Point

Floating-Point addition
Answer:

41
CE

Floating Point

Floating-Point addition
Hardware
Architecture:

Fig.10 Block diagram of an
arithmetic unit dedicated to
floating-point addition.

42
CE

Floating Point

Floating-Point multiplication
Example 1: Let’s try floating-point multiplication. We start by multiplying decimal numbers
in scientific notation by hand: 1.110ten x 1010 * 9.200ten x 10-5. Assume that we can store

only four decimal digits of the significand and two decimal digits of the exponent.
Answer 1:

43
CE

Floating Point

Floating-Point multiplication

Note: check for overflow or underflow
 the exponent still fits in its field
44
CE

Floating Point

Floating-Point multiplication

45
CE

Floating Point

Floating-Point multiplication
The algorithm for binary
floating-point multiplication
have 5 steps like the answer
section in the Example 1 in
this sector.

Fig.11 The algorithm for binary
floating-point multiplication.

46
CE

Floating Point

Floating-Point multiplication
Example 2: Binary Floating-Point multiplication. Let’s try multiplying the number 0.5ten
and -0.4375ten.
Answer 2:

47
CE

Floating Point

Floating-Point multiplication
Answer 2:

48
CE

Floating Point

Floating-Point instruction in MIPS

49
CE

Floating Point

Floating-Point instruction in MIPS
 Floating-point comparison sets a bit to true or false, depending on the comparison
condition, and a floating-point branch then decides whether or not to branch depending

on the condition.
 The MIPS designers decided to add separate floating-point registers ̶ called
$f0, $f1, $f2, … ̶ used either for single precision or double precision  they included
separate loads and stores for floating-point registers: lwcl and swcl.


The base registers for floating-point data transfers remain integer registers. The MIPS
code to load two single precision numbers from memory, add them, and then store the
sum might look like below:

50
CE

Floating Point

Floating-Point instruction in MIPS

Fig.12 MIPS floating-point architecture

51
CE

Floating Point

Floating-Point instruction in MIPS

Fig.13 MIPS floating-point architecture (cont.)

52
CE

Floating Point

FloatingPoint
instruction
in MIPS

Fig.14 MIPS
floating-point
instruction
encoding
53
CE

Floating Point

Accurate Arithmetic
 Unlike integers, which can represent exactly every number between the smallest and
largest number, floating-point numbers are normally approximations for a number they

can’t really represent.
 The reason is that an infinite variety of real numbers exists between, say, 0 and 1, but no
more than 253 can be represented exactly in double precision floating point. The best we
can do is getting the floating-point representation close to the actual number.
Thus, IEEE 754 offers several modes of rounding to let the programmer pick the
desired approximation.
 Rounding sounds simple enough, but to round accurately requires the hardware to
include extra bits in the calculation. IEEE 754, therefore, always keeps two extra bits on
the right during intermediate additions, called guard and round, respectively.
54

More Related Content

What's hot

Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
Keyur Vadodariya
 
bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)
Siddhi Viradiya
 
Control Unit Design
Control Unit DesignControl Unit Design
Control Unit Design
Vinit Raut
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
ihsanjamil
 
Stack organization
Stack organizationStack organization
Stack organization
chauhankapil
 
Quick tutorial on IEEE 754 FLOATING POINT representation
Quick tutorial on IEEE 754 FLOATING POINT representationQuick tutorial on IEEE 754 FLOATING POINT representation
Quick tutorial on IEEE 754 FLOATING POINT representation
Ritu Ranjan Shrivastwa
 
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organization
Mazin Alwaaly
 
Addressing mode Computer Architecture
Addressing mode  Computer ArchitectureAddressing mode  Computer Architecture
Addressing mode Computer Architecture
Haris456
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
Suvendu Kumar Dash
 
Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1)
Subhasis Dash
 
Carry look ahead adder
Carry look ahead adderCarry look ahead adder
Carry look ahead adder
dragonpradeep
 
Unit 1 data representation and computer arithmetic
Unit 1  data representation and computer arithmeticUnit 1  data representation and computer arithmetic
Unit 1 data representation and computer arithmetic
AmrutaMehata
 
Computer architecture control unit
Computer architecture control unitComputer architecture control unit
Computer architecture control unit
Mazin Alwaaly
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
Mazin Alwaaly
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
Operand and Opcode | Computer Science
Operand and Opcode | Computer ScienceOperand and Opcode | Computer Science
Operand and Opcode | Computer Science
Transweb Global Inc
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transfer
lavanya marichamy
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
Sanjeev Patel
 
Chapter 4 The Processor
Chapter 4 The ProcessorChapter 4 The Processor
Chapter 4 The Processorguest4f73554
 
Computer Organization and Design
Computer Organization and DesignComputer Organization and Design
Computer Organization and Design
Ra'Fat Al-Msie'deen
 

What's hot (20)

Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
 
bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)
 
Control Unit Design
Control Unit DesignControl Unit Design
Control Unit Design
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
Stack organization
Stack organizationStack organization
Stack organization
 
Quick tutorial on IEEE 754 FLOATING POINT representation
Quick tutorial on IEEE 754 FLOATING POINT representationQuick tutorial on IEEE 754 FLOATING POINT representation
Quick tutorial on IEEE 754 FLOATING POINT representation
 
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organization
 
Addressing mode Computer Architecture
Addressing mode  Computer ArchitectureAddressing mode  Computer Architecture
Addressing mode Computer Architecture
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
 
Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1)
 
Carry look ahead adder
Carry look ahead adderCarry look ahead adder
Carry look ahead adder
 
Unit 1 data representation and computer arithmetic
Unit 1  data representation and computer arithmeticUnit 1  data representation and computer arithmetic
Unit 1 data representation and computer arithmetic
 
Computer architecture control unit
Computer architecture control unitComputer architecture control unit
Computer architecture control unit
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
Operand and Opcode | Computer Science
Operand and Opcode | Computer ScienceOperand and Opcode | Computer Science
Operand and Opcode | Computer Science
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transfer
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
 
Chapter 4 The Processor
Chapter 4 The ProcessorChapter 4 The Processor
Chapter 4 The Processor
 
Computer Organization and Design
Computer Organization and DesignComputer Organization and Design
Computer Organization and Design
 

Viewers also liked

Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmeticIIUI
 
Csc1401 lecture03 - computer arithmetic - arithmetic and logic unit (alu)
Csc1401   lecture03 - computer arithmetic - arithmetic and logic unit (alu)Csc1401   lecture03 - computer arithmetic - arithmetic and logic unit (alu)
Csc1401 lecture03 - computer arithmetic - arithmetic and logic unit (alu)
IIUM
 
Arithmetic for Computers
Arithmetic for ComputersArithmetic for Computers
Arithmetic for Computers
MD. ABU TALHA
 
Booths Multiplication Algorithm
Booths Multiplication AlgorithmBooths Multiplication Algorithm
Booths Multiplication Algorithm
knightnick
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
Hareem Aslam
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
Kamal Acharya
 
Arithmetic
ArithmeticArithmetic
Arithmetic
Dan Stewart
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
Gaurav Subham
 
digital logic circuits, digital component floting and fixed point
digital logic circuits, digital component floting and fixed pointdigital logic circuits, digital component floting and fixed point
digital logic circuits, digital component floting and fixed point
Rai University
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmeticfyjordan9
 
Unit 2 arithmetics
Unit 2   arithmeticsUnit 2   arithmetics
Unit 2 arithmeticschidabdu
 
Booth algorithm
Booth algorithmBooth algorithm
Booth algorithm
Saif Al-Kalbani
 
Stop and Wait arq
Stop and Wait arqStop and Wait arq
Stop and Wait arqpramodmmrv
 
Booths algorithm for Multiplication
Booths algorithm for MultiplicationBooths algorithm for Multiplication
Booths algorithm for Multiplication
Vikas Yadav
 
Arithmetic Process in Computer Systems
Arithmetic Process in Computer SystemsArithmetic Process in Computer Systems
Arithmetic Process in Computer Systems
S N M P Simamora
 

Viewers also liked (20)

Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
 
Csc1401 lecture03 - computer arithmetic - arithmetic and logic unit (alu)
Csc1401   lecture03 - computer arithmetic - arithmetic and logic unit (alu)Csc1401   lecture03 - computer arithmetic - arithmetic and logic unit (alu)
Csc1401 lecture03 - computer arithmetic - arithmetic and logic unit (alu)
 
09 arithmetic
09 arithmetic09 arithmetic
09 arithmetic
 
Arithmetic for Computers
Arithmetic for ComputersArithmetic for Computers
Arithmetic for Computers
 
09 Arithmetic
09  Arithmetic09  Arithmetic
09 Arithmetic
 
Booths Multiplication Algorithm
Booths Multiplication AlgorithmBooths Multiplication Algorithm
Booths Multiplication Algorithm
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
 
Arithmetic
ArithmeticArithmetic
Arithmetic
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
 
digital logic circuits, digital component floting and fixed point
digital logic circuits, digital component floting and fixed pointdigital logic circuits, digital component floting and fixed point
digital logic circuits, digital component floting and fixed point
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmetic
 
IT workshop SAIKRISHNA EEE
IT workshop SAIKRISHNA EEEIT workshop SAIKRISHNA EEE
IT workshop SAIKRISHNA EEE
 
Unit 2 arithmetics
Unit 2   arithmeticsUnit 2   arithmetics
Unit 2 arithmetics
 
Booth algorithm
Booth algorithmBooth algorithm
Booth algorithm
 
Stop and Wait arq
Stop and Wait arqStop and Wait arq
Stop and Wait arq
 
Booths algorithm for Multiplication
Booths algorithm for MultiplicationBooths algorithm for Multiplication
Booths algorithm for Multiplication
 
Arithmetic Process in Computer Systems
Arithmetic Process in Computer SystemsArithmetic Process in Computer Systems
Arithmetic Process in Computer Systems
 
Stop And Wait ARQ
Stop And Wait ARQStop And Wait ARQ
Stop And Wait ARQ
 

Similar to Chapter 03 arithmetic for computers

Arithmetic for Computers.ppt
Arithmetic for Computers.pptArithmetic for Computers.ppt
Arithmetic for Computers.ppt
JEEVANANTHAMG6
 
Unit ii ca--arithmetic
Unit ii ca--arithmeticUnit ii ca--arithmetic
Unit ii ca--arithmetic
Praba haran
 
Hennchthree 160912095304
Hennchthree 160912095304Hennchthree 160912095304
Hennchthree 160912095304
marangburu42
 
Hennchthree
HennchthreeHennchthree
Hennchthree
marangburu42
 
Computer Oraganizaation.pptx
Computer Oraganizaation.pptxComputer Oraganizaation.pptx
Computer Oraganizaation.pptx
bmangesh
 
Manoch1raw 160512091436
Manoch1raw 160512091436Manoch1raw 160512091436
Manoch1raw 160512091436
marangburu42
 
3.Floating Point arith.ppt
3.Floating Point arith.ppt3.Floating Point arith.ppt
3.Floating Point arith.ppt
RavikumarR77
 
H010114954
H010114954H010114954
H010114954
IOSR Journals
 
Design and Implementation of High Speed Area Efficient Double Precision Float...
Design and Implementation of High Speed Area Efficient Double Precision Float...Design and Implementation of High Speed Area Efficient Double Precision Float...
Design and Implementation of High Speed Area Efficient Double Precision Float...
IOSR Journals
 
C++11 and 64-bit Issues
C++11 and 64-bit IssuesC++11 and 64-bit Issues
C++11 and 64-bit Issues
Andrey Karpov
 
Data representation
Data representationData representation
Data representation
Manish Kumar
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
berekethailu2
 
Number Systems.ppt
Number Systems.pptNumber Systems.ppt
Number Systems.ppt
zorogoh2
 
IS 139 Lecture 4
IS 139 Lecture 4IS 139 Lecture 4
IS 139 Lecture 4
wajanga
 
IS 139 Lecture 4 - 2015
IS 139 Lecture 4 - 2015IS 139 Lecture 4 - 2015
IS 139 Lecture 4 - 2015
Aron Kondoro
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
umardanjumamaiwada
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
umardanjumamaiwada
 

Similar to Chapter 03 arithmetic for computers (20)

Arithmetic for Computers.ppt
Arithmetic for Computers.pptArithmetic for Computers.ppt
Arithmetic for Computers.ppt
 
Unit ii ca--arithmetic
Unit ii ca--arithmeticUnit ii ca--arithmetic
Unit ii ca--arithmetic
 
Hennchthree 160912095304
Hennchthree 160912095304Hennchthree 160912095304
Hennchthree 160912095304
 
Hennchthree
HennchthreeHennchthree
Hennchthree
 
Computer Oraganizaation.pptx
Computer Oraganizaation.pptxComputer Oraganizaation.pptx
Computer Oraganizaation.pptx
 
Manoch1raw 160512091436
Manoch1raw 160512091436Manoch1raw 160512091436
Manoch1raw 160512091436
 
3.Floating Point arith.ppt
3.Floating Point arith.ppt3.Floating Point arith.ppt
3.Floating Point arith.ppt
 
H010114954
H010114954H010114954
H010114954
 
Design and Implementation of High Speed Area Efficient Double Precision Float...
Design and Implementation of High Speed Area Efficient Double Precision Float...Design and Implementation of High Speed Area Efficient Double Precision Float...
Design and Implementation of High Speed Area Efficient Double Precision Float...
 
C++11 and 64-bit Issues
C++11 and 64-bit IssuesC++11 and 64-bit Issues
C++11 and 64-bit Issues
 
Data representation
Data representationData representation
Data representation
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
 
Number Systems.ppt
Number Systems.pptNumber Systems.ppt
Number Systems.ppt
 
IS 139 Lecture 4
IS 139 Lecture 4IS 139 Lecture 4
IS 139 Lecture 4
 
IS 139 Lecture 4 - 2015
IS 139 Lecture 4 - 2015IS 139 Lecture 4 - 2015
IS 139 Lecture 4 - 2015
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Chapter 03 arithmetic for computers

  • 2. CE Arithmetic for Computers 1. Introduction 2. Addition and Subtraction 3. Multiplication 4. Division 5. Floating Point 6. Parallelism and Computer Arithmetic: Associativity 2
  • 4. CE Arithmetic for Computers 1. Introduction 2. Addition and Subtraction 3. Multiplication 4. Division 5. Floating Point 6. Parallelism and Computer Arithmetic: Associativity 4
  • 5. CE Introduction Computer words are composed of bits; thus, words can be represented as binary numbers. Chapter 2 shows that integers can be represented either in decimal or binary form, but what about the other numbers that commonly occur? For example: ■ What about fractions and other real numbers? ■ What happens if an operation creates a number bigger than can be represented? ■ And underlying these questions is a mystery: How does hardware really multiply or divide numbers? 5
  • 6. CE Arithmetic for Computers 1. Introduction 2. Addition and Subtraction 3. Multiplication 4. Division 5. Floating Point 6. Parallelism and Computer Arithmetic: Associativity 6
  • 7. CE Addition and Subtraction Addition: Binary addition, showing carries from right to left 7
  • 9. CE Addition and Subtraction Overflow When does the overflow occur on the signed number? We also need to concern: - How to detect overflow for two’s complement numbers in a computer? - What about overflow with unsigned integers? (Unsigned integers are commonly used for memory addresses where overflows are ignored.) 9
  • 10. Addition and Subtraction CE Overflow  The computer designer must therefore provide a way to ignore overflow in some cases and to recognize it in others.  The MIPS solution is to have two kinds of arithmetic instructions to recognize the two choices: ■ Add (add), add immediate (addi), and subtract (sub) cause exceptions (interrupt) on overflow. ■ Add unsigned (addu), add immediate unsigned (addiu), and subtract unsigned (subu) do not cause exceptions on overflow. Note: MIPS detects overflow with an exception, also called an interrupt on many computers. An exception or interrupt is essentially an unscheduled procedure call. 10
  • 11. CE Arithmetic for Computers 1. Introduction 2. Addition and Subtraction 3. Multiplication 4. Division 5. Floating Point 6. Parallelism and Computer Arithmetic: Associativity 11
  • 12. Multiplication CE Example Although the decimal example above happens to use only 0 and 1, multiplication of binary numbers must always use 0 and 1, and thus always offers only these two choices: 1. Just place a copy of the multiplicand (1 ×multiplicand) in the proper place if the multiplier digit is a 1. 2. Place 0 (0 ×multiplicand) in the proper place if the multiplier digit is 0. 12
  • 13. CE Multiplication Sequential Version of the Multiplication Algorithm and Hardware Fig.1: First version of the division hardware Note: Three steps are repeated 32 times to obtain the product. If each step took a clock cycle, this algorithm would require almost 100 clock cycles to multiply two 32-bit numbers. Fig.2: The first multiplication algorithm 13
  • 14. CE Multiplication Sequential Version of the Multiplication Algorithm and Hardware Example: Answer: Step by step follow the multiplication algorithm 14
  • 15. CE Multiplication Sequential Version of the Multiplication Algorithm and Hardware Fig.3 Refine version of the multiplication hardware  Compare with the first version in the previous slide, the Multiplicand register, ALU, and Multiplier register are all 32 bits wide, with only the Product register left at 64 bits.  It just takes one clock cycle to get the Product. 15
  • 16. CE Multiplication Signed Multiplication  The easiest way to understand how to deal with signed numbers is to first convert the multiplier and multiplicand to positive numbers and then remember the original signs.  The algorithms should then be run for 31 iterations, leaving the signs out of the calculation.  It turns out that the last algorithm will work for signed numbers. 16
  • 18. CE Multiplication Multiply in MIPS  MIPS provides a separate pair of 32-bit registers to contain the 64-bit product, called Hi and Lo.  To produce a properly signed or unsigned product, MIPS has two instructions: multiply (mult) and multiply unsigned (multu).  To fetch the integer 32-bit product, the programmer uses move from lo (mflo). The MIPS assembler generates a pseudo instruction for multiply that specifies three general purpose registers, generating mflo and mfhi instructions to place the product into registers. 18
  • 19. CE Arithmetic for Computers 1. Introduction 2. Addition and Subtraction 3. Multiplication 4. Division 5. Floating Point 6. Parallelism and Computer Arithmetic: Associativity 19
  • 20. CE Division  The reciprocal operation of multiply is divide, an operation that is even less frequent and even more quirky.  It even offers the opportunity to perform a mathematically invalid operation: dividing by 0. Example: 20
  • 21. CE Division A division algorithm and hardware Fig.5 First version of the multiplication hardware Note: both the dividend and the divisor are positive and hence the quotient and the remainder are nonnegative. The division operands and both results are 32-bit values, and we will ignore the sign for now. Fig.6 The first division algorithm 21
  • 22. CE Division The division algorithm and hardware Example: Answer: Step by step follow the multiplication algorithm 22
  • 23. Division CE A faster division hardware Fig.7 The improved version of the division hardware 23
  • 24. Division CE Signed division  The simplest solution is to remember the signs of the divisor and dividend and then negate the quotient if the signs disagree.  The one complication of signed division is that we must also set the sign of the remainder. Remember that the following equation must always hold: Dividend = Quotient x Divisor + Remainder  Remainder = Dividend – (Quotient x Divisor) Example: 24
  • 25. CE Division Divide in MIPS  You may have already observed that the same sequential hardware can be used for both multiply and divide in Fig.3 and Fig.7 .  The only requirement is a 64-bit register that can shift left or right and a 32-bit ALU that adds or subtracts. Hence, MIPS uses the 32-bit Hi and 32-bit Lo registers for both multiply and divide.  As we might expect from the algorithm above, Hi contains the remainder, and Lo contains the quotient after the divide instruction completes.  To handle both signed integers and unsigned integers, MIPS has two instructions: divide (div) and divide unsigned (divu).  The MIPS assembler allows divide instructions to specify three registers, generating the mflo or mfhi instructions to place the desired result into a general-purpose register. 25
  • 26. CE Arithmetic for Computers 1. Introduction 2. Addition and Subtraction 3. Multiplication 4. Division 5. Floating Point 6. Parallelism and Computer Arithmetic: Associativity 26
  • 27. CE Floating Point Definitions Some representations of the real number:  The alternative notation for the above last two numbers is called scientific notation, which has a single digit to the left of the decimal point.  A number in scientific notation that has no leading 0s is called a normalized number Example: 1.0ten x 10-9: normalized scientific number 0.1ten x 10-8: not normalized scientific number 10.0ten x 10-10: not normalized scientific number  The binary number shown in scientific notation is called floating point Floating point: Computer arithmetic that represents numbers in which the binary point is not fixed. 27
  • 28. CE Floating Point Floating-Point representation  A designer of a floating-point representation must find a compromise between the size of the fraction and the size of the exponent. This tradeoff is between precision and range: - Increasing the size of the fraction enhances the precision of the fraction. - Increasing the size of the exponent increases the range of numbers that can be represented.  Floating-point numbers are usually a multiple of the size of a word. The representation of a MIPS floating-point number: Where s is the sign of the floating-point number (1 meaning negative) exponent is the value of the 8-bit exponent field (including the sign of the exponent) fraction is the 23-bit number This representation is called sign and magnitude, since the sign is a separate bit from the rest of the number. 28 In general, floating-point numbers are of the form:
  • 29. Floating Point CE Floating-Point representation  Overflow (floating-point): A situation in which a positive exponent becomes too large to fit in the exponent field.  Underflow (floating-point): A situation in which a negative exponent becomes too large to fit in the exponent field. To reduce chances of underflow or overflow is to offer another format that has a larger exponent. In C this number is called double, and operations on doubles are called double precision floating-point arithmetic; single precision floating-point is the name of the format in previous slide. Double precision: A floating-point value represented in two 32-bit words. Single precision: A floating-point value represented in a single 32-bit word. The representation of a double precision floating-point number: Where: s is the sign of the floating-point number (1 meaning negative) exponent is the value of the 11-bit exponent field (including the sign of the exponent) fraction is the 52-bit number 29
  • 30. CE Floating Point Floating-Point representation  These above formats go beyond MIPS. They are part of the IEEE 754 floating-point standard (IEEE 754), found in virtually every computer invented since 1980.  To pack even more bits into the significand (also coefficient or mantissa is part of a number in scientific notation), IEEE 754 makes the leading 1-bit of normalized binary numbers implicit. Hence, the number is actually 24 bits long in single precision (implied 1 and a 23-bit fraction), and 53 bits long in double precision (1 +52). Note: To be precise, we use the term significand to represent the 24- or 53-bit number that is 1 plus the fraction, and fraction when we mean the 23- or 52-bit number.  The representation of the rest of the numbers uses the form from before with the hidden 1 added where the bits of the fraction represent a number between 0 and 1 and E specifies the value in the exponent field. If we number the bits of the fraction from left to rights1, s2, s3, . . . ,then the value is: 30
  • 31. CE Floating Point Floating-Point representation  Negative exponents pose a challenge to simplified sorting. If we use two’s complement or any other notation in which negative exponents have a 1 in the most significant bit of the exponent field. Example:  1.0two x 2-1 would be represented with a negative exponent will look like a big number.  1.0two x 2+1 would be represented with a negative exponent will look like the smaller number. 31
  • 32. CE Floating Point Floating-Point representation  The desirable notation must therefore represent the most negative exponent as 00 . . . 00two and the most positive as 11 . . . 11two. This convention is called biased notation, with the bias being the number subtracted from the normal, unsigned representation to determine the real value.  IEEE 754 uses a bias of 127 for single precision, so an exponent of -1 is represented by the bit pattern of the value (-1 + 127ten ), or 126ten = 0111 1110two , and +1 is represented by (1+127), or 128ten = 1000 0000two .  The exponent bias for double precision is 1023.  Importance: Biased exponent means that value represented by a floating-point number is really: The range of single precision number is from as small as to as large as Fig.8: IEEE 754 encoding of floating-point numbers 32
  • 36. CE Floating Point Floating-Point representation Example 2: Converting Binary to Decimal Floating-Point Answer 2: 36
  • 37. CE Floating Point Floating-Point addition Let’s add numbers in scientific notation by hand to illustrate the problem in floatingpoint addition: 9.999ten x 101 + 1.610ten x 10-1. Assume that we can store only four decimal digits of the significand and two decimal digits of the exponent. 37
  • 38. CE Floating Point Floating-Point addition Note: check for overflow or underflow  the exponent still fits in its field 38
  • 39. CE Floating Point Floating-Point addition The algorithm for binary floating-point addition. Fig.9 The algorithm for binary floating-point addition. 39
  • 40. CE Floating Point Floating-Point addition Example: Try adding the number 0.5ten and -0.4375ten in binary using the algorithm in Fig.9 Answer: 40
  • 42. CE Floating Point Floating-Point addition Hardware Architecture: Fig.10 Block diagram of an arithmetic unit dedicated to floating-point addition. 42
  • 43. CE Floating Point Floating-Point multiplication Example 1: Let’s try floating-point multiplication. We start by multiplying decimal numbers in scientific notation by hand: 1.110ten x 1010 * 9.200ten x 10-5. Assume that we can store only four decimal digits of the significand and two decimal digits of the exponent. Answer 1: 43
  • 44. CE Floating Point Floating-Point multiplication Note: check for overflow or underflow  the exponent still fits in its field 44
  • 46. CE Floating Point Floating-Point multiplication The algorithm for binary floating-point multiplication have 5 steps like the answer section in the Example 1 in this sector. Fig.11 The algorithm for binary floating-point multiplication. 46
  • 47. CE Floating Point Floating-Point multiplication Example 2: Binary Floating-Point multiplication. Let’s try multiplying the number 0.5ten and -0.4375ten. Answer 2: 47
  • 50. CE Floating Point Floating-Point instruction in MIPS  Floating-point comparison sets a bit to true or false, depending on the comparison condition, and a floating-point branch then decides whether or not to branch depending on the condition.  The MIPS designers decided to add separate floating-point registers ̶ called $f0, $f1, $f2, … ̶ used either for single precision or double precision  they included separate loads and stores for floating-point registers: lwcl and swcl.  The base registers for floating-point data transfers remain integer registers. The MIPS code to load two single precision numbers from memory, add them, and then store the sum might look like below: 50
  • 51. CE Floating Point Floating-Point instruction in MIPS Fig.12 MIPS floating-point architecture 51
  • 52. CE Floating Point Floating-Point instruction in MIPS Fig.13 MIPS floating-point architecture (cont.) 52
  • 53. CE Floating Point FloatingPoint instruction in MIPS Fig.14 MIPS floating-point instruction encoding 53
  • 54. CE Floating Point Accurate Arithmetic  Unlike integers, which can represent exactly every number between the smallest and largest number, floating-point numbers are normally approximations for a number they can’t really represent.  The reason is that an infinite variety of real numbers exists between, say, 0 and 1, but no more than 253 can be represented exactly in double precision floating point. The best we can do is getting the floating-point representation close to the actual number. Thus, IEEE 754 offers several modes of rounding to let the programmer pick the desired approximation.  Rounding sounds simple enough, but to round accurately requires the hardware to include extra bits in the calculation. IEEE 754, therefore, always keeps two extra bits on the right during intermediate additions, called guard and round, respectively. 54

Editor's Notes

  1. Note:chỉgiớithiệuthamkhảo
  2. SummaryMultiplication hardware is simply shifts and add, derived from the paper-and pencil method learned in grammar school. Compilers even use shift instructions for multiplications by powers of 2.
  3. SummaryThe common hardware support for multiply and divide allows MIPS to provide a single pair of 32-bit registers that are used both for multiply and divide. Figure 3.13summarizes the additions to the MIPS architecture for the last two sections.
  4. Real E = Bias E – Bias(127)