0% found this document useful (0 votes)
7 views

Computer Architecture unit 3

The document provides an overview of instruction codes, CPU design, and the instruction cycle, detailing how computers execute operations through a structured process. It explains the components of instruction codes, various addressing modes, and the roles of the CPU's memory unit, control unit, and arithmetic logic unit (ALU). Additionally, it outlines the steps involved in the instruction cycle, including fetching, decoding, and executing instructions.

Uploaded by

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

Computer Architecture unit 3

The document provides an overview of instruction codes, CPU design, and the instruction cycle, detailing how computers execute operations through a structured process. It explains the components of instruction codes, various addressing modes, and the roles of the CPU's memory unit, control unit, and arithmetic logic unit (ALU). Additionally, it outlines the steps involved in the instruction cycle, including fetching, decoding, and executing instructions.

Uploaded by

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

UNIT -3

Instruction Codes

While a Program, as we all know, is, A set of instructions that specify the operations, operands, and
the sequence by which processing has to occur. An instruction code is a group of bits that tells the
computer to perform a specific operation part.

Instruction Code: Operation Code

The operation code of an instruction is a group of bits that define operations such as add, subtract,
multiply, shift and compliment. The number of bits required for the operation code depends upon
the total number of operations available on the computer. The operation code must consist of at
least n bits for a given 2^n operations. The operation part of an instruction code specifies the
operation to be performed.

Instruction Code: Register Part

The operation must be performed on the data stored in registers. An instruction code therefore
specifies not only operations to be performed but also the registers where the operands (data) will
be found as well as the registers where the result has to be stored.

Stored Program Organisation


The simplest way to organize a computer is to have Processor Register and instruction code with two
parts. The first part specifies the operation to be performed and second specifies an address. The
memory address tells where the operand in memory will be found.
Instructions are stored in one section of memory and data in another.

Computers with a single processor register is known as Accumulator (AC). The operation is
performed with the memory operand and the content of AC.
Common Bus System
The basic computer has 8 registers, a memory unit and a control unit. Paths must be provided to
transfer data from one register to another. An efficient method for transferring data in a system is to
use a Common Bus System. The output of registers and memory are connected to the common bus.

Load(LD)
The lines from the common bus are connected to the inputs of each register and data inputs of
memory. The particular register whose LD input is enabled receives the data from the bus during the
next clock pulse transition.
Before studying about instruction formats lets first study about the operand address parts.
When the 2nd part of an instruction code specifies the operand, the instruction is said to
have immediate operand. And when the 2nd part of the instruction code specifies the address of an
operand, the instruction is said to have a direct address. And in indirect address, the 2nd part of
instruction code, specifies the address of a memory word in which the address of the operand is
found.

Computer Instructions
The basic computer has three instruction code formats. The Operation code (opcode) part of the
instruction contains 3 bits and remaining 13 bits depends upon the operation code encountered.
There are three types of formats:
1. Memory Reference Instruction

It uses 12 bits to specify the address and 1 bit to specify the addressing mode (I). I is equal
to 0 for direct address and 1 for indirect address.

2. Register Reference Instruction


These instructions are recognized by the opcode 111 with a 0 in the left most bit of instruction. The
other 12 bits specify the operation to be executed.

3. Input-Output Instruction
These instructions are recognized by the operation code 111 with a 1 in the left most bit of
instruction. The remaining 12 bits are used to specify the input-output operation.

Format of Instruction
The format of an instruction is depicted in a rectangular box symbolizing the bits of an instruction.
Basic fields of an instruction format are given below:
1. An operation code field that specifies the operation to be performed.

2. An address field that designates the memory address or register.

3. A mode field that specifies the way the operand of effective address is determined.

Computers may have instructions of different lengths containing varying number of addresses. The
number of address field in the instruction format depends upon the internal organization of its
registers.

Addressing Modes and Instruction Cycle

The operation field of an instruction specifies the operation to be performed. This operation will be
executed on some data which is stored in computer registers or the main memory. The way any
operand is selected during the program execution is dependent on the addressing mode of the
instruction. The purpose of using addressing modes is as follows:

1. To give the programming versatility to the user.


2. To reduce the number of bits in addressing field of instruction.

Types of Addressing Modes


Below we have discussed different types of addressing modes one by one:

Immediate Mode

In this mode, the operand is specified in the instruction itself. An immediate mode instruction has an
operand field rather than the address field.

For example: ADD 7, which says Add 7 to contents of accumulator. 7 is the operand here.

Register Mode

In this mode the operand is stored in the register and this register is present in CPU. The instruction
has the address of the Register where the operand is stored.
Advantages

 Shorter instructions and faster instruction fetch.

 Faster memory access to the operand(s)

Disadvantages

 Very limited address space

 Using multiple registers helps performance but it complicates the instructions.

Register Indirect Mode


In this mode, the instruction specifies the register whose contents give us the address of operand
which is in memory. Thus, the register contains the address of operand rather than the operand
itself.

Auto Increment/Decrement Mode

In this the register is incremented or decremented after or before its value is used.

Direct Addressing Mode

In this mode, effective address of operand is present in instruction itself.


 Single memory reference to access data.

 No additional calculations to find the effective address of the operand.

For Example: ADD R1, 4000 - In this the 4000 is effective address of operand.

NOTE: Effective Address is the location where operand is present.

Indirect Addressing Mode

In this, the address field of instruction gives the address where the effective address is stored in
memory. This slows down the execution, as this includes multiple memory lookups to find the
operand.

Displacement Addressing Mode

In this the contents of the indexed register is added to the Address part of the instruction, to obtain
the effective address of operand.

EA = A + (R), In this the address field holds two values, A(which is the base value) and R(that holds the
displacement), or vice versa.
Relative Addressing Mode

It is a version of Displacement addressing mode.

In this the contents of PC(Program Counter) is added to address part of instruction to obtain the
effective address.

EA = A + (PC), where EA is effective address and PC is program counter.

The operand is A cells away from the current cell(the one pointed to by PC)

Base Register Addressing Mode


It is again a version of Displacement addressing mode. This can be defined as EA = A + (R), where A is

displacement and R holds pointer to base address.

Stack Addressing Mode


In this mode, operand is at the top of the stack. For example: ADD, this instruction will POP top two
items from the stack, add them, and will then PUSH the result to the top of the stack.

Instruction Cycle

An instruction cycle, also known as fetch-decode-execute cycle is the basic operational process of a
computer. This process is repeated continuously by CPU from boot up to shut down of computer.

Following are the steps that occur during an instruction cycle:


1. Fetch the Instruction
The instruction is fetched from memory address that is stored in PC(Program Counter) and stored in
the instruction register IR. At the end of the fetch operation, PC is incremented by 1 and it then points

to the next instruction to be executed.

2. Decode the Instruction


The instruction in the IR is executed by the decoder.

3. Read the Effective Address

If the instruction has an indirect address, the effective address is read from the memory. Otherwise
operands are directly read in case of immediate operand instruction.

4. Execute the Instruction


The Control Unit passes the information in the form of control signals to the functional unit of CPU.

The result generated is stored in main memory or sent to an output device.


The cycle is then repeated by fetching the next instruction. Thus in this way the instruction cycle is
repeated continuously.
CPU Design
CPU design involves creating the central processing unit of a computer, a key component
responsible for executing instructions and performing calculations. It's a complex process
involving hardware, software, and system design, ultimately determining the computer's
performance. Key elements of CPU design include the arithmetic logic unit (ALU), control unit
(CU), memory components (registers, caches), and clock circuitry.

Central Processing Unit (CPU)

CPU [Central Processing Unit]. It is the brain of the computer. It is the part that does most of the
work in a computer system. Just like how our brain controls our body and processes information,
the CPU carries out instructions from programs and performs calculations. It’s made up of
smaller components that work together to execute tasks, making it the heart of any computing
device.
All types of data processing operations from simple arithmetic to complex tasks 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. The CPU’s job is to make
sure everything runs smoothly and efficiently.

What is a CPU?

A Central Processing Unit is the most important component of a computer system. A CPU is
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.

Different Parts of CPU

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


 Memory or Storage Unit
 Control Unit
 ALU(Arithmetic Logic Unit)
Let us now look at the block diagram of the computer:
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. 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. Its 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 that is input from the
memory unit, interpret them, and then direct 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: By arithmetic operations, we mean operations like addition, subtraction,
multiplication, and division, and all these operations 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: The 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 instructions and produce an output.
CPU work 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 decoding begins.
 Execute: After the decode step the instructions are ready to execute.
 Store: After the execute step the instructions are ready to store in the memory.

A simple CPU design

A simple CPU design involves a core loop of fetching instructions from memory, decoding them,
and executing them. The CPU repeatedly fetches the next instruction from memory, decodes the
instruction to determine the operation and operands, and then executes the operation using the
appropriate data paths.

1. Instruction Fetch:

 The Program Counter (PC) holds the address of the next instruction to be executed.

 The PC's value is loaded into the Memory Address Register (MAR).

 The CPU requests the memory to read the instruction at the address in MAR.

 The instruction is fetched from memory and loaded into the Instruction Register (IR).

 The PC is incremented to point to the next instruction.


2. Instruction Decode:

 The control unit analyzes the instruction in the IR.


 It determines the operation (e.g., add, subtract, load) and any operands.

 This information is used to set up the necessary data paths for execution.
3. Instruction Execute:

 The CPU uses the decoded instruction to perform the specified operation.

 Data is moved along the data paths to the appropriate units (e.g., ALU) for processing.

 Results are stored in registers or memory.

 The cycle repeats, fetching the next instruction from the incremented PC.

Data Paths:

 System Bus: The main pathway for data transfer between different CPU components and
memory.

 Memory Bus: Facilitates communication between the CPU and memory (e.g., RAM).

 Internal Bus: Connects the CPU's internal units (e.g., ALU, registers).

 Control Signals: These signals determine the direction and timing of data flow along the data
paths.
Example:

Imagine an instruction to add two values stored in registers A and B, and store the result in
register C.

1. The CPU fetches the instruction from memory.

2. It decodes the instruction to understand it's an addition operation involving registers A, B, and C.

3. It routes the values from registers A and B to the ALU via the system bus.

4. The ALU performs the addition, and the result is placed on the bus.

5. The result is transferred from the bus to register C.

6. The cycle repeats, preparing to fetch the next instruction.

You might also like