1 of 30

Unit No 3�Computer Arithmetic

  • The arithmetic and logic Unit
  • Integer representation
  • Integer arithmetic
  • Floating point representation
  • Floating point arithmetic
  • Introduction of arithmetic co-processor.

2 of 30

Arithmetic and logic Unit

  • What is an arithmetic-logic unit (ALU)?
  • An arithmetic-logic unit is the part of a central processing unit that carries out arithmetic and logic operations on the operands in computer instruction words.
  • In some processors, the ALU is divided into two units: an arithmetic unit (AU) and a logic unit (LU).
  • Some processors contain more than one AU -- for example, one for fixed-point operations and another for floating-point operations.
  • In computer systems, floating-point computations are sometimes done by a floating-point unit (FPU) on a separate chip called a numeric coprocessor.

3 of 30

Different operation as carried out by ALU can be categorized as follows –

  • logical operations − These include operations like AND, OR, NOT, XOR, NOR, NAND, etc.
  • Bit-Shifting Operations − This pertains to shifting the positions of the bits by a certain number of places either towards the right or left, which is considered a multiplication or division operations.
  • Arithmetic operations − This refers to bit addition and subtraction. Although multiplication and division are sometimes used, these operations are more expensive to make. Multiplication and subtraction can also be done by repetitive additions and subtractions respectively.

4 of 30

5 of 30

  • Configurations of the ALU
  • The description of how ALU interacts with the processor is given below. Every arithmetic logic unit includes the following configurations:
  • Instruction Set Architecture
  • Accumulator
  • Stack
  • Register to Register
  • Register Stack
  • Register Memory

6 of 30

  • Accumulator
  • The intermediate result of every operation is contained by the accumulator, which means Instruction Set Architecture (ISA) is not more complex because there is only required to hold one bit.
  • Stack
  • Whenever the latest operations are performed, these are stored on the stack that holds programs in top-down order, which is a small register. When the new programs are added to execute, they push to put the old programs.
  • Register-Register Architecture
  • It includes a place for 1 destination instruction and 2 source instructions, also known as a 3-register operation machine. This Instruction Set Architecture must be more in length for storing three operands, 1 destination and 2 sources. 

7 of 30

  • Register - Stack Architecture
  • Generally, the combination of Register and Accumulator operations is known as for Register - Stack Architecture. The operations that need to be performed in the register-stack Architecture are pushed onto the top of the stack. And its results are held at the top of the stack. 
  • Register and Memory
  • In this architecture, one operand comes from the register, and the other comes from the external memory as it is one of the most complicated architectures. The reason behind it is that every program might be very long as they require to be held in full memory space. Generally, this technology is integrated with Register-Register Register technology and practically cannot be used separately.

8 of 30

Advantages of ALU�

  • ALU has various advantages, which are as follows:
  • It supports parallel architecture and applications with high performance.
  • It has the ability to get the desired output simultaneously and combine integer and floating-point variables.
  • It has the capability of performing instructions on a very large set and has a high range of accuracy.
  • Two arithmetic operations in the same code like addition and multiplication or addition and subtraction, or any two operands can be combined by the ALU. For case, A+B*C.
  • Through the whole program, they remain uniform, and they are spaced in a way that they cannot interrupt part in between.
  • In general, it is very fast; hence, it provides results quickly.
  • There are no sensitivity issues and no memory wastage with ALU.
  • They are less expensive and minimize the logic gate requirements.

9 of 30

Disadvantages of ALU�

  • The disadvantages of ALU are discussed below:
  • With the ALU, floating variables have more delays, and the designed controller is not easy to understand.
  • The bugs would occur in our result if memory space were definite.
  • It is difficult to understand amateurs as their circuit is complex; also, the concept of pipelining is complex to understand.
  • A proven disadvantage of ALU is that there are irregularities in latencies.
  • Another demerit is rounding off, which impacts accuracy.

10 of 30

Introduction of arithmetic co-processor:-

  • If in microprocessor chip, new circuitry can be added with special purpose to perform special tasks or to perform operations on numbers in order to offload the work of the core CPU. The CPU can then work faster.
  • We may use a conveyor belt to do some extra work while motor is running. So , the motor is more effectively utilized. Similarly, supplementary processor, i.e.,  a co-processor handles the mathematical part of the work when we run complex applications.
  • A supplementary processor like a Coprocessor is mainly used in computers to achieve special tasks like graphical display processing & wide arithmetic calculations. This processor is is designed to perform such tasks very efficiently as compared to the CPU, thus overall computer speed can be increased. 

11 of 30

What is a coprocessor ?

  • A co-processor is many times referred as a Math Processor. As the coprocessor performs routine mathematical tasks, the core processor is freed up from this computation and its time is saved. By taking specialized processing tasks from core CPU, coprocessor reduces the strain on the main microprocessor, so that it can run at a greater speed.
  • A coprocessor can perform  special tasks like complex mathematical calculations or graphical display processing. They perform such jobs faster than core CPU. As a result, overall computer speed of the system increases.
  • To an ARM processor, we can attach the coprocessors. A coprocessor when added, we need to   expand instruction set of Core CPU or add configurable registers,  to increase the processing power. The coprocessor interface permits a couple of coprocessor to be connected to the ARM CPU.

12 of 30

How does coprocessor work ?

  • Coprocessors assists the system in running more efficiently by offloading specific tasks of the CPU. They can be 
  • Independent type – �It work in an asynchronous manner with the CPU . Whenever it performs any task/ some calculations, that is not synchronized with the CPU. Co-processor can take decisions independently here. CPU can then do its own work without worrying about co-processor’s work. Instead of synchronously waiting, CPU that issued the request is freed up to perform another task.
  • Direct control type –  �Direct control type such as floating-point units – controlled by coprocessor’s instructions that are CPU instruction set’s part. The CPU that initiated the request waits or  checks until co-processor completes operation. The coprocessor is not independent here & is governed or controlled by the main CPU. CPU & coprocessor works in synchronization here.

13 of 30

Coprocessor Architecture

14 of 30

Properties of Coprocessor  :

  1. Without primary microprocessor, coprocessor cannot function.
  2. Main processor has to identify and segregate computationally intensive instructions in a program.
  3. The instructions which have an intensive amount of calculations are performed by coprocessor.
  4. The main processor handles all other activities.

15 of 30

Advantages�

  • The advantages of a coprocessor include the following.
  • The co-processor simply handles more specialized tasks faster as compared to the core CPU
  • These processors are easy to use and the most popular.
  • It decreases the microprocessor’s strain by taking special processing tasks from the CPU so that it runs at a higher speed.
  • This processor is helpful in extending the CPU’s processing features by expanding the instruction set or by offering configuration registers.

16 of 30

Disadvantages�

  • The disadvantages of coprocessors include the following.
  • The coprocessor is not capable in recovering instructions from memory, directly executing instructions, managing memory, I/O operations performing
  • It depends on the main processor to regain coprocessor instructions & take care of all other operations not related to the coprocessor.
  • This is not the major processor of the system.
  • The coprocessor cannot work without the main microprocessor.

17 of 30

Applications�

  • The applications of coprocessors include the following.
  • The co-processor is used to perform some of the more specialized tasks such as graphical display processing or complex mathematical calculations.
  • A co-processor is simply used for reducing the burden on the CPU of a computer.
  • This processor works with the CPU of the computer side-by-side.
  • This processor performs high-level mathematical operations much faster as compared to the main processor like roots, logarithms, trigonometry functions, etc.
  • A coprocessor increases the primary processor’s functions.
  • The coprocessor performs different operations like signal processing, floating-point arithmetic, string processing, graphics, I/O interfacing through peripheral devices, cryptography, etc.
  • These processors are stand-alone chips in earlier desktop computers that were connected to the motherboard.
  • A coprocessor handles the CPU tasks for boosting overall performance.

18 of 30

Difference between Processor and Coprocessor

Processor

Coprocessor

The processor is the main processing unit in the computer that executes different arithmetic, logic & control operations based on the instructions.

The coprocessor is a special processor that gives support to the main processor.

 

The processor takes care of all the main works

 

The coprocessor takes care of some other things only like graphics & arithmetic calculations.

It handles logical operations & mathematical calculations and generates control signals to other components for synchronizing the tasks.

It performs signal processing, mathematical operations, networking & cryptography based on the type.

The processor maintains the entire computer’s proper functioning.

This processor helps in increasing the performance of the system and offloads severe tasks from the CPU.

19 of 30

INTEGER REPRESENTATION

UNSIGNED SIGNED

SIGN MAGNITUDE

  • 1’s complement
  • 2’s complement

  • Represents only positive numbers (including 0)
  • No sign bit is used
  • All bits represent the value (magnitude)

Used to represent both positive and negative numbers

There are 3 methods:

20 of 30

UNSIGNED INTEGER –

An unsigned integer is a number that does not have a sign bit, meaning:

It can store only non-negative values (0 and positive numbers)

All bits are used to represent the magnitude (value)

No. of bits

Range

8

0 to 255

16

0 to 65535

Ex: Store 5 bit in 8-bit memory location

Change the given decimal number into binary i.e. 5 = 101

Make it a 8-bit number i.e. 5 = 00000101

21 of 30

SIGN MAGNITUDE REPRESENTATION –

In this representation, the MSB (MOST SIGNIFICANT BIT) is used as a sign bit to indicate the sign of the integer.�The remaining 7 bits represent the magnitude (absolute value).�In the signed magnitude both positive as well as negative values are used.

  • For positive numbers, the MSB is 0
  • For negative numbers, the MSB is 1

Ex: For 5 –�In binary form it can be written as +5 = 101

An 8 bit representation is shown as – 00000101�(MSB → sign bit, remaining bits → absolute value)

For -5 –�Binary form of 5 is 101

An 8 bit representation can be shown as – 10000101

22 of 30

  • 1’s Complement
  • It uses the MSB (Most Significant Bit) as the sign bit
  • For positive numbers, all bits remain the same
  • For negative numbers, all bits of the corresponding positive number are flipped (0 → 1, 1 → 0)
  • Example:
  • Decimal number: 7
  • Binary of 7: 111
  • In 8-bit form:
    • +7 = 00000111
    • -7 = 11111000 (1’s complement of +7)

23 of 30

  • 2’s Complement
  • It uses MSB to represent the sign bit
  • For positive numbers the representation is same as in sign magnitude & 1’s complement
  • For negative numbers first perform the 1’s complement and then add 1 at the LSB
  • Example:
  • For +7 = 00000111�For -7 –
  • First remove 1’s complement by inverting all the bits of the positive number.�We get, Inverted bits → 11111000
  • 2’s complement → 11111000�+ 1�11111001

24 of 30

  • Example: For 12
  • Binary of 12 (8-bit):
  • +12 = 00001100
  • Step 1: Find 1’s complement (invert bits)
  • 11110011
  • Step 2: Add 1
  • 1111001 1

+ 1

11110100

25 of 30

What is Floating Point Representation?�

The Floating point representation is a way to the encode numbers in a format that can handle very large and very small values. It is based on scientific notation where numbers are represented as a fraction and an exponent. In computing, this representation allows for trade-off between range and precision.

Format: A floating point number is typically represented as:

Value=Sign × Significand × BaseExponent

where:

  • Sign: Indicates whether the number is positive or negative.
  • Significand (Mantissa): Represents the precision bits of the number.
  • Base: Usually 2 in binary systems.
  • Exponent: Determines the scale of the number.

26 of 30

Need for Floating Point Representation

The Floating point representation is crucial because:

  • Range: It can represent a wide range of values from the very large to very small numbers.
  • Precision: It provides a good balance between the precision and range, making it suitable for the scientific computations, graphics and other applications where exact values and wide ranges are necessary.
  • Flexibility: It adapts to different scales of numbers allowing for the efficient storage and computation of real numbers in the computer systems.

Number System and Data Representation

  • Number Systems: The Floating point representation often uses binary (base-2) systems for the digital computers. Other number systems like decimal (base-10) or hexadecimal (base-16) may be used in the different contexts.
  • Data Representation: This includes how numbers are stored in the computer memory involving binary encoding and the representation of the various data types.

27 of 30

Table – Precision Representation

Precision

Base

Sign

Exponent

Significant

Single precision

2

1

8

23+1

Double precision

2

1

11

52+1

28 of 30

Single Precision Format�

The single precision format has 23 bits for significant (1 represents implied bit, details below), 8 bits for exponent and 1 bit for sign. 

For example, the rational number 9÷2 can be converted to single precision float format as following,

9(10) ÷ 2(10) = 4.5(10) = 100.1(2)

29 of 30

Double Precision Format

The double precision format has 52 bits for significant (1 represents implied bit), 11 bits for exponent and 1 bit for sign. All other definitions are same for double precision format, except for the size of various components. 

Advantages

  • Wide Range: Can represent very large and very small numbers.
  • Efficient Calculation: The Suitable for a wide range of the scientific, engineering and graphics applications where precision and range are important.
  • Standardization: The Floating point representation is standardized (IEEE 754) which ensures consistency and compatibility across the different systems and programming languages.

30 of 30

Disadvantages

  • Precision Issues: The Floating point numbers can suffer from the precision errors due to rounding and truncation.
  • Complexity: The More complex than fixed-point representation requiring more computational resources.
  • Overhead: Operations involving the floating point numbers can be slower and require more memory compared to integer operations.

Applications

  • Scientific Computations: Used in simulations, modeling and calculations requiring the high precision and large ranges.
  • Graphics: Essential in the rendering and manipulating graphical data where precise calculations are needed.
  • Engineering: The Applied in fields such as aerospace, mechanical engineering and electronics for the accurate measurements and simulations.