fectching and executing instructions

Download Report

Transcript fectching and executing instructions

Question
• What technology differentiates the different
stages a computer had gone through from
generation 1 to present?
CPU STRUCTURE AND
ORGANISATION
INTRODUCTION
• At the heart of Microcomputer system lies the
CPU or Processor
• To understand the organization of the CPU,
we shall consider the requirements placed on
the CPU (things it must do)
• Processor fetches and executes instructions.
• This chapter outlines the way in which this is
done using a highly simplified processor
PROCESSOR Functions
• Processor runs a program by repeatedly
fetching and executing instructions from main
memory.
• CPU reads an instruction from memory
• Interprets the instruction to determine what
action is required
• Fetches data, execution may require reading
data from memory or an I/O module
PROCESSOR Functions
• Processes data, the execution may require
performing some arithmetic or logical
operation on the data
• Write data, the result of an execution may
require writing data to memory or an I/O
module.
Processor Organization
• We recall that the processor has two major
components. ALU for computation or
processing of data and Control Unit which
controls the movement data and instruction
into and out of the CPU, controls the
operation of the ALU.
• Besides the major components the processor
will need some form of memory to be able to
carry out the designated task, Register.
Register Organization
• CPU has a set or registers that function as a level of
memory above main memory.
• A register is a small high speed memory location used
for temporary storage of data or control information.
• The registers are employed to control the operation
of the CPU.
• They are not visible to a user.
• Four registers are essential to the instruction
execution.
• PC, MAR, IR,MBR
Registers
• PC, contains the address of an instruction to
be fetched
• IR, contains the instruction most recently
fetched
• MAR, contains the address of a location in
memory
• MBR, contains a word of data to be written to
memory or word most recently read.
Processor-Memory Interconnection
• In Microcomputer system, the processor is
connected to main memory by a data,
address and control bus.
• A program consists of a series of instructions
or actions to be carried out by the processor
• Actions are performed on data
• Instructions and data are stored in primary or
main memory during program execution
Interconnections
• Registers are connected together by an
internal data path or bus.
• The flow of data along this bus is managed by
the control unit.
Fetching Instructions
• When running a program, the processor
fetches instructions by providing an address
on the address bus and reading the instruction
from the data bus
• The processor uses the four internal registers
to carry out the task .
Continued
• The CPU updates the PC after an instruction
has been fetched such that it points to the
next instruction to be executed. A branch or
skip instruction will also modify the contents
of the PC.
• The fetched instruction is loaded into the IR
• Data is exchanged with the memory using
the MAR and MBR.
Fetching Instructions
• Before running a program , the PC must be
initialized with the address of the first instruction.
• Then the instruction cycle begins once the address
stored in the PC is transferred along the processor’s
internal data bus into the MAR.
• Instruction cycle involve three main steps; fetch,
execute and interrupt.
• Once in the MAR, the instruction address is passed
along the address bus to the memory unit.
Fetching Instructions
• PC is then incremented to the next
instruction. This helps the CPU to keep track
of where it is in the program.
• As the memory unit decodes the address
provided on the address bus and locates the
memory cell containing the instruction, the
processor generates a read signal on the
control bus
Fetching Instructions
• Memory unit then responds by placing a copy
of the contents of this memory location on
the data bus
• Instruction is now copied form the data bus
and latched in to the MBR
• MBR interfaces processor’s internal bus to the
external data bus
Fetching Instructions
• After buffering a copy, processor now transfers the
instruction along its internal data bus into the IR.
• Once in the IR, the instruction is decoded by the
control unit, which generates a sequence of control
signals form the information provided by the
instruction’s operation code
• The control signals initiates events
• This completes the fetch part of the instruction cycle.
Fetching Instructions
• Processor enters an execute phase, which
varies according to the type of operation
specified in the instruction .
• There are two types of instruction formats
• Machine instruction and Assembly language
instruction.
Machine Instructions
• Instruction are manipulated by a computer in binary
form.
• All instructions are represented in binary form and
this is called machine code.
• Logically the instruction is composed of two fields
i.e. opcode and operation address
• Opcode specifies the type of operation the processor
is to perform
• Operation address specifies the address of the data
Assembly Language instructions
• It is easier to write and understand programs when
instructions are represented symbolically like move
4, add 5 rather than the machine language.
• Most low level language programs are written in
assembly language.
• Each instruction will be translated into machine code
before the program can be loaded into memory and
executed by the processor, carried out by an
assembler
Executing Instructions
• After the fetch process, its then time to
execute the instruction.
• From the instruction register, the data forming the instruction
is decoded by the control unit. It then passes the decoded
information as a sequence of control signals to the relevant
function units of the CPU to perform the actions required by
the instruction such as reading values from registers, passing
them to the Arithmetic logic unit (ALU) to add them together
and writing the result back to a register.
Execution
• To support instruction execution, the processor uses
the data Register and the ALU
• ALU is a logic block which performs a limited
number of arithmetic and logic operations.
• It operates upon data that has been stored in data
register or which has been buffered in the MBR
• After performing any operation, the content of data
register is overwritten with any results produced
Execution
• The cycle of fetching and executing
instructions is called the fetch-execute cycle
and its repeated until the program is
terminated in some way. E.g. stop
Summary
• Programs are executed by repeatedly fetching
instructions from memory in to the processor
and then executing them. This is called fetchexecute cycle
• Three buses are used to exchange
information with the memory unit: address
bus, data bus and control bus
• To organize the flow of instructions, the
processor uses a number of special purpose
registers.
Summary
• Instruction decoding is performed by the control
unit which generates appropriate control signals in
response to the opcode of the instruction.
• The operand field is used to specify the address of
any data required by the instruction .
• The ALU is used to carry out arithmetic and logic
operations on data, temporarily stored in the data
register or passed to it from the MBR.