Computer Architecture unit 3
Computer Architecture 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.
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.
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.
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.
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.
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.
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:
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
Disadvantages
In this the register is incremented or decremented after or before its value is used.
For Example: ADD R1, 4000 - In this the 4000 is effective address of operand.
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.
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
In this the contents of PC(Program Counter) is added to address part of instruction to obtain the
effective address.
The operand is A cells away from the current cell(the one pointed to by PC)
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.
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.
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.
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 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).
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.
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.
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.