0% found this document useful (0 votes)
23 views15 pages

CO Unit 3-1

Uploaded by

deeph6131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views15 pages

CO Unit 3-1

Uploaded by

deeph6131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

UNIT 3

Central Processing Unit : Introduction, General Register organization, Stack Organisation,


Instruction Formats, Addressing Modes, Data transfer and manipulation, Program Control.

Central Processing Unit :

The full form of CPU is Central Processing Unit . It is a brain of the computer. All types of data
processing operations and all the important functions of a computer are performed by the CPU. It helps
input and output devices to communicate with each other and perform their respective operations. It also
stores data which is input, intermediate results in between processing, and instructions.

What is a CPU?

A Central Processing Unit is the most important component of a computer system. A CPU is a hardware
that performs data input/output, processing and storage functions for a computer system. A CPU can be
installed into a CPU socket. These sockets are generally located on the motherboard. CPU can perform
various data processing operations. CPU can store data, instructions, programs, and intermediate results.

History of CPU

Since 1823, when Baron Jons Jakob Berzelius discovered silicon, which is still the primary component
used in the manufacture of CPUs today, the history of the CPU has experienced numerous significant
turning points. The first transistor was created by John Bardeen, Walter Brattain, and William Shockley
in December 1947. in 1958, the first working integrated circuit was built by Robert Noyce and Jack
Kilby.

The Intel 4004 was the company’s first microprocessor, which it unveiled in 1971. Ted Hoff’s assistance
was needed for this. When Intel released its 8008 CPU in 1972, Intel 8086 in 1976, and Intel 8088 in June
1979, it contributed to yet another win. The Motorola 68000, a 16/32-bit processor, was also released in
1979. The Sun also unveiled the SPARC CPU in 1987. AMD unveiled the AM386 CPU series in March
1991.

In January 1999, Intel introduced the Celeron 366 MHZ and 400 MHz processors. AMD back in April
2005 with it’s first dual-core processor. Intel also introduced the Core 2 Dual processor in 2006. Intel
released the first Core i5 desktop processor with four cores in September 2009.

In January 2010, Intel released other processors like Core 2 Quad processor Q9500, the first Core i3 and
i5 mobile processors, first Core i3 and i5 desktop processors.

In June 2017, Intel released Core i9 desktop processor, and Intel introduced its first Core i9 mobile
processor In April 2018.

Different Parts of CPU

Now, the CPU consists of 3 major units, which are:

1. Memory or Storage Unit

2. Control Unit

3. ALU(Arithmetic Logic Unit)

Let us now look at the block diagram of the computer:


Here, in this diagram, the three major components are also shown. So, let us discuss these major
components:

Memory or Storage Unit

As the name suggests this unit can store instructions, data, and intermediate results. The memory unit is
responsible for transferring information to other units of the computer when needed. It is also known as
an internal storage unit or the main memory or the primary storage or Random Access Memory
(RAM) as all these are storage devices.

Its size affects speed, power, and performance. There are two types of memory in the computer, which
are primary memory and secondary memory. Some main functions of memory units are listed below:

 Data and instructions are stored in memory units which are required for processing.

 It also stores the intermediate results of any calculation or task when they are in process.

 The final results of processing are stored in the memory units before these results are released to
an output device for giving the output to the user.

 All sorts of inputs and outputs are transmitted through the memory unit.

Control Unit

As the name suggests, a control unit controls the operations of all parts of the computer but it does not
carry out any data processing operations. For executing already stored instructions, It instructs the
computer by using the electrical signals to instruct the computer system. It takes instructions from the
memory unit and then decodes the instructions after that it executes those instructions. So, it controls the
functioning of the computer. It’s main task is to maintain the flow of information across the processor.
Some main functions of the control unit are listed below:

 Controlling of data and transfer of data and instructions is done by the control unit among other
parts of the computer.
 The control unit is responsible for managing all the units of the computer.

 The main task of the control unit is to obtain the instructions or data which is input from the
memory unit, interprets them, and then directs the operation of the computer according to that.

 The control unit is responsible for communication with Input and output devices for the transfer
of data or results from memory.

 The control unit is not responsible for the processing of data or storing data.

ALU (Arithmetic Logic Unit)

ALU (Arithmetic Logic Unit) is responsible for performing arithmetic and logical functions or
operations. It consists of two subsections, which are:

 Arithmetic Section

 Logic Section

Now, let us know about these subsections:

Arithmetic Section: By arithmetic operations, we mean operations like addition, subtraction,


multiplication, and division, and all these operation and functions are performed by ALU. Also, all the
complex operations are done by making repetitive use of the mentioned operations by ALU.

Logic Section: By Logical operations, we mean operations or functions like selecting, comparing,
matching, and merging the data, and all these are performed by ALU.

Note: CPU may contain more than one ALU and it can be used for maintaining timers that help run the
computer system.

What Does a CPU Do?

The main function of a computer processor is to execute instruction and produce an output. CPU work
are Fetch, Decode and Execute are the fundamental functions of the computer.

 Fetch: the first CPU gets the instruction. That means binary numbers that are passed from RAM
to CPU.

 Decode: When the instruction is entered into the CPU, it needs to decode the instructions. with
the help of ALU(Arithmetic Logic Unit) the process of decode begins.

 Execute: After decode step the instructions are ready to execute

 Strore: After execute step the instructions are ready to store in the memory.

Types of CPU

We have three different types of CPU:

 Single Core CPU: The oldest type of computer CPUs is single core CPU. These CPUs were used
in the 1970s. these CPUs only have a single core that preform different operations. This means
that the single core CPU can only process one operation at a single time. single core CPU CPU is
not suitable for multitasking.
 Dual-Core CPU: Dual-Core CPUs contain a single Integrated Circuit with two cores. Each core
has its cache and controller. These controllers and cache are work as a single unit. dual core CPUs
can work faster than the single-core processors.

 Quad-Core CPU: Quad-Core CPUs contain two dual-core processors present within a single
integrated circuit (IC) or chip. A quad-core processor contains a chip with four independent cores.
These cores read and execute various instructions provided by the CPU. Quad Core CPU
increases the overall speed for programs. Without even boosting the overall clock speed it results
in higher performance.

Registers

In Computer Architecture, the Registers are very fast computer memory which is used to execute
programs and operations efficiently. but In that scenario, registers serve as gates, sending signals to
various components to carry out little tasks. Register signals are directed by the control unit, which also
operates the registers.

The following list of five registers for in-out signal data storage:

1. Program Counter
A program counter (PC) is a CPU register in the computer processor which has the address of the
next instruction to be executed from memory. As each instruction gets fetched, the program
counter increases its stored value by 1. It is a digital counter needed for faster execution of tasks
as well as for tracking the current execution point.

2. Instruction Register
In computing, an instruction register (IR) is the part of a CPU’s control unit that holds the
instruction currently being executed or decoded. The instruction register specifically holds the
instruction and provides it to the instruction decoder circuit.

3. Memory Address Register


The Memory Address Register (MAR) is the CPU register that either stores the memory address
from which data will be fetched from the CPU, or the address to which data will be sent and
stored. It is a temporary storage component in the CPU(central processing unit) that temporarily
stores the address (location) of the data sent by the memory unit until the instruction for the
particular data is executed.

4. Memory Data Register


The memory data register (MDR) is the register in a computer’s processor, or central processing
unit, CPU, that stores the data being transferred to and from the immediate access storage.
Memory data register (MDR) is also known as memory buffer register (MBR).

5. General Purpose Register


General-purpose registers are used to store temporary data within the microprocessor. It is a
multipurpose register. They can be used either by a programmer or by a user.

General Register Organization

When we are using multiple general-purpose registers, instead of a single accumulator register, in the
CPU Organization then this type of organization is known as General register-based CPU Organization.
In this type of organization, the computer uses two or three address fields in their instruction format. Each
address field may specify a general register or a memory word. If many CPU registers are available for
heavily used variables and intermediate results, we can avoid memory references much of the time, thus
vastly increasing program execution speed, and reducing program size.

For example:

MULT R1, R2, R3

This is an instruction of an arithmetic multiplication written in assembly language. It uses three address
fields R1, R2, and R3. The meaning of this instruction is:

R1 <-- R2 * R3

This instruction also can be written using only two address fields as:

MULT R1, R2

In this instruction, the destination register is the same as one of the source registers. This means the
operation

R1 <-- R1 * R2

The use of a large number of registers results in a short program with limited instructions.

Some examples of General register-based CPU Organizations are IBM 360 and PDP- 11.

Features of a General Register based CPU organization:

Registers: In this organization, the CPU contains a set of registers, which are small, high-speed memory
locations used to store data that is being processed by the CPU. The general-purpose registers can be used
to store any type of data, including integers, floating-point numbers, addresses, and control information.

Operand access: The CPU accesses operands directly from the registers, rather than having to load them
from memory each time they are needed. This can significantly improve performance, as register access
is much faster than memory access.

Data processing: The CPU can perform arithmetic and logical operations directly on the data stored in
the registers. This eliminates the need to transfer data between the registers and memory, which can
further improve performance.

Instruction format: The instruction format used in a General Register based CPU typically includes
fields for specifying the operands and operation to be performed. The operands are identified by register
numbers, rather than memory addresses.

Context switching: Context switching in a General Register based CPU involves saving the contents of
the registers to memory, and then restoring them when the process resumes. This is necessary to allow
multiple processes to share the CPU.

The advantages of General register-based CPU organization –

 The efficiency of the CPU increases as large number of registers are used in this organization.

 Less memory space is used to store the program since the instructions are written in a compact
way.

The disadvantages of General register based CPU organization –


 Care should be taken to avoid unnecessary usage of registers. Thus, compilers need to be more
intelligent in this aspect.

 Since a large number of registers are used, thus extra cost is required in this organization.

General register CPU organization of two types:

1. Register-memory reference architecture (CPU with less register) –


In this organization Source 1 is always required in the register, source 2 can be present either in
the register or in memory. Here two address instruction formats are compatible instruction
formats.

2. Register-register reference architecture (CPU with more register) –


In this organization, ALU operations are performed only on registered data. So operands are
required in the register. After manipulation, the result is also placed in a register. Here three
address instruction formats are the compatible instruction format.

Stack Organization –

The computers which use Stack-based CPU Organization are based on a data structure called a stack.
The stack is a list of data words. It uses the Last In First Out (LIFO) access method which is the most
popular access method in most of the CPU. A register is used to store the address of the topmost element
of the stack which is known as Stack pointer (SP). In this organization, ALU operations are performed
on stack data. It means both the operands are always required on the stack. After manipulation, the result
is placed in the stack.

The main two operations that are performed on the operators of the stack are Push and Pop. These two
operations are performed from one end only.

1. Push –
This operation results in inserting one operand at the top of the stack and it increases the stack pointer
register. The format of the PUSH instruction is:

PUSH

It inserts the data word at a specified address to the top of the stack. It can be implemented as:

// Increment SP by 1

SP <-- SP + 1

//store the content of specified memory address

//into SP; i.e, at top of stack

SP <-- (memory address)

2. Pop –
This operation results in deleting one operand from the top of the stack and decreasing the stack pointer
register. The format of the POP instruction is:

POP

It deletes the data word at the top of the stack to the specified address. It can be implemented as:
//transfer the content of SP (i.e, at top most data)

//into specified memory location

(memory address) <-- SP

//Decrement SP by 1

SP <-- SP - 1

Operation type instruction does not need the address field in this CPU organization. This is because the
operation is performed on the two operands that are on the top of the stack. For example:

SUB

This instruction contains the opcode only with no address field. It pops the two top data from the stack,
subtracting the data, and pushing the result into the stack at the top.

PDP-11, Intel’s 8085, and HP 3000 are some examples of stack-organized computers.

The advantages of Stack-based CPU organization –

 Efficient computation of complex arithmetic expressions.

 Execution of instructions is fast because operand data are stored in consecutive memory
locations.

 The length of instruction is short as they do not have an address field.

The disadvantages of Stack-based CPU organization –

 The size of the program increases.

Note: Stack-based CPU organization uses zero address instruction.

Instruction Formats –

Introduction:

In computer organization, instruction formats refer to the way instructions are encoded and represented in
machine language. There are several types of instruction formats, including zero, one, two, and three-
address instructions. Here is a brief overview of each:

Zero-address instructions, One-address instructions, Two-address instructions, Three-address


instructions. Each type of instruction format has its own advantages and disadvantages in terms of code
size, execution time, and flexibility. Modern computer architectures typically use a combination of these
formats to provide a balance between simplicity and power.

A computer performs a task based on the instruction provided. Instruction in computers comprises groups
called fields. These fields contain different information as for computers everything is in 0 and 1 so each
field has different significance based on which a CPU decides what to perform. The most common fields
are:

 Operation field specifies the operation to be performed like addition.

 Address field which contains the location of the operand, i.e., register or memory location.
 Mode field which specifies how operand is to be founded.

Instruction is of variable length depending upon the number of addresses it contains. Generally, CPU
organization is of three types based on the number of address fields:

1. Single Accumulator organization

2. General register organization

3. Stack organization

In the first organization, the operation is done involving a special register called the accumulator. In
second on multiple registers are used for the computation purpose. In the third organization the work on
stack basis operation due to which it does not contain any address field. Only a single organization
doesn’t need to be applied, a blend of various organizations is mostly what we see generally.

Based on the number of address, instructions are classified as:

Note that we will use X = (A+B)*(C+D) expression to showcase the procedure.

Zero Address Instructions –

These instructions do not specify any operands or addresses. Instead, they operate on data stored in
registers or memory locations implicitly defined by the instruction. For example, a zero-address
instruction might simply add the contents of two registers together without specifying the register names.

A stack-based computer does not use the address field in the instruction. To evaluate an expression first it
is converted to reverse Polish Notation i.e. Postfix Notation.

Expression: X = (A+B)*(C+D)

Postfixed : X = AB+CD+*

TOP means top of stack

M[X] is any memory location


PUSH A TOP = A

PUSH B TOP = B

ADD TOP = A+B

PUSH C TOP = C

PUSH D TOP = D

ADD TOP = C+D

TOP =
MUL
(C+D)*(A+B)

POP X M[X] = TOP

Advantages: They are simple and can be executed quickly since they do not require any operand fetching
or addressing. They also take up less memory space.

Disadvantages: They can be limited in their functionality and do not allow for much flexibility in terms of
addressing modes or operand types.

2 .One Address Instructions –

These instructions specify one operand or address, which typically refers to a memory location or
register. The instruction operates on the contents of that operand, and the result may be stored in the same
or a different location. For example, a one-address instruction might load the contents of a memory
location into a register.

This uses an implied ACCUMULATOR register for data manipulation. One operand is in the
accumulator and the other is in the register or memory location. Implied means that the CPU already
knows that one operand is in the accumulator so there is no need to specify it.

Expression: X = (A+B)*(C+D)

AC is accumulator
M[] is any memory location

M[T] is temporary location

LOAD A AC = M[A]

ADD B AC = AC + M[B]

STORE T M[T] = AC

LOAD C AC = M[C]

ADD D AC = AC + M[D]

MUL T AC = AC * M[T]

STORE X M[X] = AC

Advantages: They allow for a wide range of addressing modes, making them more flexible than zero-
address instructions. They also require less memory space than two or three-address instructions.

Disadvantages: They can be slower to execute since they require operand fetching and addressing.

3.Two Address Instructions –

These instructions specify two operands or addresses, which may be memory locations or registers. The
instruction operates on the contents of both operands, and the result may be stored in the same or a
different location. For example, a two-address instruction might add the contents of two registers together
and store the result in one of the registers.

This is common in commercial computers. Here two addresses can be specified in the instruction. Unlike
earlier in one address instruction, the result was stored in the accumulator, here the result can be stored at
different locations rather than just accumulators, but require more number of bit to represent address.

Here destination address can also contain operand.

Expression: X = (A+B)*(C+D)

R1, R2 are registers


M[] is any memory location

MOV R1, A R1 = M[A]

ADD R1, B R1 = R1 + M[B]

MOV R2, C R2 = M[C]

ADD R2, D R2 = R2 + M[D]

MUL R1, R2 R1 = R1 * R2

MOV X, R1 M[X] = R1

Advantages: They allow for more complex operations and can be more efficient than one-address
instructions since they allow for two operands to be processed in a single instruction. They also allow for
a wide range of addressing modes.

Disadvantages: They require more memory space than one-address instructions and can be slower to
execute since they require operand fetching and addressing.

4.Three Address Instructions –

These instructions specify three operands or addresses, which may be memory locations or registers. The
instruction operates on the contents of all three operands, and the result may be stored in the same or a
different location. For example, a three-address instruction might multiply the contents of two registers
together and add the contents of a third register, storing the result in a fourth register.

This has three address field to specify a register or a memory location. Program created are much short in
size but number of bits per instruction increase. These instructions make creation of program much easier
but it does not mean that program will run much faster because now instruction only contain more
information but each micro operation (changing content of register, loading address in address bus etc.)
will be performed in one cycle only.

Expression: X = (A+B)*(C+D)

R1, R2 are registers

M[] is any memory location


ADD R1, A, B R1 = M[A] + M[B]

ADD R2, C, D R2 = M[C] + M[D]

MUL X, R1, R2 M[X] = R1 * R2

Advantages: They allow for even more complex operations and can be more efficient than two-address
instructions since they allow for three operands to be processed in a single instruction. They also allow
for a wide range of addressing modes.

Disadvantages: They require even more memory space than two-address instructions and can be slower
to execute since they require operand fetching and addressing.
Overall, the choice of instruction format depends on the specific requirements of the computer
architecture and the trade-offs between code size, execution time, and flexibility.

Addressing Modes–

For executing an instruction, data are required. These data may be present in the accumulator (AC) or
stored in some location in the memory. There are various ways to specify the address of data or more
precisely operands.These are known as addressing modes.

The techniques for specifying the address of the operands are known as addressing modes. The address
of an operand is known as the effective address.

Some common addressing modes are listed below.

1) Direct (or absolute) addressing : In this mode of addressing, the instruction contains the
address of data (operand) in the memory. The operand will be present at some location in the
memory and its address in memory is provided in the instruction itself. That is, the address
field of the instruction contains the effective address. For example BUN A Branch
to the instruction in memory location A LDA A Load the operand
stored at memory location A into accumulator(AC)
2) Register addresing : In register addressing mode, the operands are located in registers of the
register set. The instruction then specifies the address of register. For example:
AND R1 Do AND
operation between the values of register AC and R1 MOV R1,R2 Transfer data
stored in register R1 to register R2.
3) Register Indirect addressing: In register indirect addressing mode, the instruction specifies
the register which contains address of the operand in memory. The operand is present at some
location in memory and its address is contained in a register. In the indirect addressing mode,
the instruction specifies the address of this register. That is, the operand address is given
indirectly by the instruction. Hence, this method is called Register Indirect Addressing Mode.
4) Immediate addressing: In this case, the operand itself is given in the instruction. For
example:
LDA 10101 [It means, Load operand 10101 into AC]
5) Implicit addressing: In implicit addressing mode, the location of operand is understood from
the instruction itself. That is, the operands are specified implicitly in the definition of the
instruction. For example, the instruction CMA (CoMplement Accumulator) implicitly
specifies that the operand is in the accumulator.
6) Indexed addressing: Indexed addressing mode makes use of a register called index register.
This register contains the address of the operand with respect to a fixed memory address. The
instruction specifies the fixed address. To access an operand the value in the index register is
added with the fixed value given in the instruction. Therefore, if the index register is
incremented after each instruction, the same instruction can be used to access elements stored
in consecutive memory locations.
7) Base addressing: The vase addressing mode is opposite to indexed addressing mode in its
functioning. Unlike indexed addressing mode, in this case the fixed address is stored in a
register called base register. The distance of operand from this fixed address is provided in the
instruction. It is similar to indexed addressing mode in that during instruction execution, the
address given in the address field of the instruction is added to the value in base register.
8) Relative addressing: In relative addressing mode, the contents of program counter are added
to the address in the address field of instruction. The sum of these values then provides the
effective address of the operand. Suppose, for example, the program counter contains value
500, then the instruction BUN 23 will make CPU to execute instruction located at address
523(500 + 23 = 523)

Data Transfer and Manipulation:


What is Data Transfer?

In computer architecture, data transfer refers to the movement of data between different components
within a computer system. These components can include the central processing unit (CPU), memory,
storage devices, and input/output (I/O) devices. Data transfer within a computer system occurs through
the use of a bus, which is a set of communication lines that allow different components to communicate
with each other.

There are several types of data transfer that can occur within a computer system. These include:

1. Memory transfer: This refers to the movement of data between the CPU and main memory (e.g.,
RAM). Memory transfer is an important part of the CPU's operation, as it allows the CPU to
access and manipulate data stored in the memory.

2. I/O transfer: This refers to the movement of data between the CPU and I/O devices, such as
keyboards, mice, and printers.

3. Storage transfer: This refers to the movement of data between the CPU and storage devices such
as hard drives and solid-state drives.

4. Inter-processor communication: This refers to the movement of data between different CPUs
within a computer system such as in a multi-core processor or a cluster of computers.

What is Data Manipulation?


Data manipulation in computer architecture refers to the various operations that can be performed on data
stored in a computer system. These operations may include sorting, filtering, merging and transforming
data as well as extracting and summarizing data from large data sets.

There are many different technique and tools that can be used to manipulate data in a computer system,
including programming languages, databases and data processing frameworks. Some common data
manipulation technique includes:

 Sorting: Sorting data involves rearranging the records in a dataset based on the values of one or
more fields. This can be useful for organizing data in a more logical or meaningful way or for
making it easier to find specific records.

 Filtering: Filtering data involves selecting only a subset of the records in a dataset based on
certain criteria. This can be useful for isolating specific records that are of particular interest.

 Merging: Merging data involves combining two or more datasets into a single dataset. This can
be useful for combining data from different sources or for combining data from different time
periods.

 Transforming: Transforming data involves altering the values of one or more fields in a dataset.
This can be useful for cleaning or standardization of data or for converting data from one format
to another.

 Extracting and Summarizing: Extracting and summarizing data involves selecting and
summarizing specific data points from a larger dataset. This can be useful for generating reports
or for creating more manageable datasets for further analysis.

Steps for Data Manipulation

There are several steps involved in data manipulation which may vary depending on the specific goals
requirements of the task at hand. In general, the steps involved in data manipulation can include:

1. Gathering data: The first step in data manipulation is often to gather the data that you will be
working with. This may involve accessing data stored in a database, extracting data from a file or
API or collecting data manually.

 Cleaning and preprocessing data: Once you have gathered your data, the next step is often to
clean and preprocess it. This may involve correcting errors, removing duplicate records or filling
in missing values.

 Transforming and manipulating data: After your data has been cleaned and preprocessed, you
can begin to transfer and manipulate it as needed. This may involve sorting data, filtering records,
merging datasets or converting data from one format to another.

 Analyzing and visualizing data: Once you have transformed and manipulated your data, you can
begin to analyze and visualize it. This may involve generating summary statistics, creating charts
and graphs or performing more advanced statistical analysis.

 Storing and organizing data: After you have finished manipulating and analyzing your data, it is
important to store and organize it in a way that makes it easy to access and use in the future. This
may involve saving data to a database or file system or creating a system for organizing and
categorizing data.
Program Control

The CPU while executing a program normally executes the instructions sequentially, i.e. one after
another. After executing an instruction the next instruction in squence is executed. The PC (Program
Counter) is incremented each time to point to the next instruction in sequence.

But, when some instructions, called Program Control instructions (like Branch to a location, Jump to a
location, Call a subroutine, Handle interrupt etc.), are executed, the value in Program Counter is changed.
This would cause an alteration in the program flow.

The sequential execution of program also causes ptogram flow alteration. Every interrupt is associated
with a subroutine, also called a service routine, which will handle it. When the CPU encounters as
interrupt, it transfers its attention from a currently running program to the service routine. Control returns
to the original program after the service program is executed. The same holds true for other program
control operations. In order to return to the same stage of the previous program where it had left, certain
things need to be saved before jumping to a subroutine. These are:

a) The content of the Program Counter (PC)


b) The contents of all Processor registers
c) The contents of status register

Stack comes very handy for storing the return address, where to the CPU has to return after executing a
subroutine, especially in cases of recursive subroutines. A recursive subroutine is a subroutine that calls
itself. If a single register is used for storing the return address, when the recursive subroutine calls itself,
the previously stored return address is destroyed. This will not happen if a stack is used. The return
addresses can be pushed into the stack, without distroying any previous values.

You might also like