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

Computer Organization Architecture - Topic 4

The CPU is the central processing unit of a computer. It performs arithmetic and logical operations and controls the flow of data and instructions. The three main components of a CPU are the control unit, arithmetic logic unit, and registers. The control unit controls the movement of data and instructions. The ALU performs arithmetic and logical operations. Registers are storage locations used for holding data and instructions during processing. The fetch cycle is the first part of the instruction cycle, where the CPU fetches the next instruction from memory.

Uploaded by

asj233510377
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Computer Organization Architecture - Topic 4

The CPU is the central processing unit of a computer. It performs arithmetic and logical operations and controls the flow of data and instructions. The three main components of a CPU are the control unit, arithmetic logic unit, and registers. The control unit controls the movement of data and instructions. The ALU performs arithmetic and logical operations. Registers are storage locations used for holding data and instructions during processing. The fetch cycle is the first part of the instruction cycle, where the CPU fetches the next instruction from memory.

Uploaded by

asj233510377
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 67

TOPIC 4:

CENTRAL PROCESSING UNIT


TCS1063: COMPUTER ORGANIZATION & ARCHITECTURE
Component
s of CPU

Role of Register
Type of
statement • User visible
Register
• Control Status
CPU Register
Organization
Assembly
Language
Element Register
Organization
Fetch

CENTRAL
PROCESSING Indirect
Instruction
UNIT Cycle
Expression
evaluation
(Infix, Stack Interrup
Postfix) Immediate
Displacement t Execute
Addressing
• PC Relative
• Index Register
• Base Register Direct
Addressing
Operation
(PUSH, Addressing
Register-
POP)
Indirect
Mode
Addressing Indirect
Addressing
Register-
Direct
Addressing
INTRODUCTION
• CPU is a single microprocessor made from a
semiconducting material (silicon)
• Main function  perform arithmetic and logical
operations on data
• Controlled by a computer program
Task of CPU
CPU reads an instruction from
Fetch instructions memory

The instruction is decoded to


Interpret instructions determine what action is
required

Reading data from memory or


Fetch data I/O

Perform arithmetic and logical


Process data operation

Writing data to memory or


Write data I/O
Control Unit
Registers
(CU)

Arithmetic & CPU


Logic Unit (ALU) Interconnection
Component
of CPU
ALU
• Performs arithmetic and logical operations

CU
• Controls the movement of data, instructions and the operation of ALU

Register
• A set of storage locations

CPU Interconnection
• Internal processor bus - The data transfer and logic control paths
REGISTER ORGANIZATION
• Enable to minimize
User- main memory
Visible references by
Register optimizing use of
registers

Role of
Register
• Used to control the
Control operation of the
And Status processor and to
Register control the execution
of programs
User- Visible Register
• Can be assigned to a variety
functions • Used only to hold data
• Contain the operand for any • Cannot be employed in the
op-code calculation
• Used for addressing function General
Data
Purpose
Register
Register

Condition
Codes Address
Register Register
• May be devoted to a
(or Flags)
• Condition codes are bits set addressing mode
• Example: segment pointers,
by the processor hardware
index registers, stack
pointer
Control And Status Register
• Function: To control the operation of the processor
• Registers:
Memory Buffer
Program Counter Instruction Memory Address
Register
(PC) Register (IR) Register (MAR)
(MBR/MDR)

Contains the
Contains the Contains a
address of Contains the
instruction word of data
an address of a
most to be written
instruction location in
recently or most
to be memory
fetched recently read
fetched
INSTRUCTION CYCLE
Read the next
Save the current
instruction from
process state and FETCH
memory
service the interrupt

INTERRUPT INDIRECT

The instruction is
EXECUTE
decoded to determine
Interpret the opcode
what action is
and perform the
required
operation
Data Flow
• The exact sequence of events during an instruction cycle
depends on the design of the processor
• Connected to • Connected to data
address line Memory lines
• Specifies the Memory Buffer • Contains the value
Address
address for a read Register (MBR) to be stored or the
or write operation Register (MAR) last value read from
memory

Holds the address of Program Instruction Holds the last


next instruction to be Counter (PC) Register (IR) instruction fetched
fetched
The Fetch Cycle
• Fetch cycle occurs at the beginning of instruction cycle
• An instruction to be fetched from memory
2
3
The PC contains the address of The address is moved to 4
the next instruction to be the MAR and placed on The control unit
fetched the address bus requests a memory read

7
PC is incremented by 1,
1
prepare for the next
fetch An instruction to be
fetched from
memory

5
6
The result is placed
Then copied into the MBR on the data bus
and then moved to the IR

Data Flow, Fetch Cycle


2
Then the control unit
requests a memory read
The Indirect Cycle

3
Get the desired
address of the
operand into the MBR

The address reference in


MBR is transferred to the
MAR
Data Flow, Indirect Cycle
The Execute Cycle
• The execute cycle takes many forms
• Depends on which of the various machine instructions is
in the IR
• This cycle involve:
• Transferring data among registers
• Read or write from memory or I/O
• The invocation of the ALU
4 3
1 The PC is loaded with The special memory location
The current contents the address of the reserved for this purpose is
of the PC must be interrupt routine loaded into the MAR from the
saved control unit
The Interrupt Cycle

As a result, the next


instruction cycle will begin
by fetching the
appropriate instruction

2 The contents of the PC are


transferred to the MBR to
be written into memory

Data Flow, Interrupt Cycle


ADDRESSING MODES
• Addressing modes  Refers to the way in which the
operand of an instruction is specified
• Objective: Be able to reference a large range of locations in
main memory or virtual memory

The opcode is the instruction that is executed by the CPU and


the operand is the data or memory location used to execute
that instruction.
• Most common addressing techniques :

Immediate Direct Indirect Register

Register
Displacement Stack
Indirect
• For the purpose of references, we use notation:

A = Contents of the address field in the instruction


R = Contents of an address field in the instruction that
refers to a register
EA = Actual (effective) address of the location containing
the referenced operand
(X) = Contents of location X
Immediate Addressing
• The simplest form of addressing
• The operand is present in the instruction

Operand = Address Field


Operand = A
• This mode can be used to define and use constants or set
initial values of variables
• Advantages:
• No memory reference to fetch data
• Fast
• Disadvantage : Limited range – size of number is restricted to
size of address field
Direct Addressing
• The address field contains the
effective address of the operand
EA =A

• It requires only one memory


reference
• No special calculation
• Disadvantage: A limited address
space
Indirect Addressing
• It has the address field refer to the
address of a word in memory (the
address of the operand)
EA = (A)
• Memory cell pointed to by
address field contains the address
of (pointer to) the operand
 The parentheses means the contents of
 Advantage: An address space of 2N is now available for a word
length of N.
 Disadvantage: The instruction execution requires two
memory references to fetch the operand: one to get its
address and a second to get its value.
Register Addressing
• Similar to direct addressing
• Address field refers to a register
• Operand is in register
• Instruction can be executed within
the CPU without the need to refer
to memory for operand
EA = R
• Advantages:
• Very small address field needed
• Very fast execution
• Disadvantage:
• Very limited address space
Register Indirect Addressing
• Similar to indirect addressing
• The address field refers to a
memory location or a register
EA = (R)

• The advantages and limitations


 similar to indirect
addressing
Displacement Addressing
• Combination of direct and
indirect addressing
EA = ( R ) + A

Program Index
Counter Register
(PC) (XR)

Base
Register
(B)
• It requires that the instruction have two address fields:
• Address field 1: Contain value = A, used directly
• Address field 2: Contain a register, the contents are added
to A to produce the effective address
• Three addressing technique:

PC Relative Index Register Base Register


Addressing Addressing Addressing
• The content of PC • The content of • The content of
is added to the index register (XR) base register (B) is
address part of the is added to the added to the
instruction to address part of the address part of the
obtain the instruction to instruction to
effective address obtain the obtain the
• EA = PC + A effective address effective address
• EA = XR + A • EA = B + A
Base Register Addressing
B
Stack
• Stack  An ordered set of elements, only one of which can
be accessed at a time
• The point of access  top of the stack
• The number of elements in the stack is variable
• The last element in the stack  base of the stack
• Items only be added to or deleted from the top of the stack
Operation using stack:
• PUSH  Appends/ Add one new item to the top
• POP  Removes a top item
Expression Evaluation

Infix Postfix
Notation Notation
@ Reverse Polish
Method Notation
Infix Notation
• Mathematical formulas are expressed in infix
notation
• A binary operator appears between the operands
(e.g. A + B)
• For complex expressions, parentheses are used to
determine the order of evaluation of expressions
• To minimize the use of parentheses, operations
have an implied precedence
Postfix Notation
• The operator follows its two operands
• Example
a+b ab+
a + (b x c)  a b c x +
(a + b) x c  a b + c x
• No parentheses are required
• Advantage: An expression in this form is easily
evaluated using a stack
• Example: f = (a - b) / (c + d * e)
• Solution:
(a - b) / (c + d * e)
a b - c d e * + /
• Procedure for Postfix notation
2a

Variable or
2 constant: Push 3
it onto the stack
After the
expression has
Scan for each of been scanned,
1
element: the result is on
Operator: Pop the top of the
An expression is the top two stack
scanned from items, perform
left to right the operation,
and push the
result
2b
• Example: f = (a - b) / (c + d * e)
• Solution: a b – c d e * + /
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
two items, perform the
operation, and push
the result

a
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
two items, perform the
operation, and push
the result
b

a
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
two items, perform the
operation, and push
the result

a–b
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
two items, perform the
operation, and push
the result
c

a–b
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
d two items, perform the
operation, and push
the result
c

a–b
• Solution: a b – c d e * + /

Remember!!
If the element is ..

e • Variable or constant:
Push it onto the stack
• Operator: Pop the top
d two items, perform the
operation, and push
the result
c

a–b
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
d*e two items, perform the
operation, and push
the result
c

a–b
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
two items, perform the
operation, and push
the result
(d * e) + c

a–b
• Solution: a b – c d e * + /

Remember!!
If the element is ..

• Variable or constant:
Push it onto the stack
• Operator: Pop the top
two items, perform the
operation, and push
the result

a–b
(d * e) + c
ASSEMBLY LANGUAGE

Augmented by additional
A symbolic representation of types of statements that
the machine language facilitate program writing

Assembly
Language

Each instruction is
translated into machine
Provide instructions to the instruction by the
assembler assembler
Advantages: Disadvantages:
• Debugging and verifying • Development time
• Making compilers • Reliability and security
• Embedded systems • Maintainability
• Hardware drivers and • Portability
system code
• Function libraries:
Assembly Language Elements

Label Mnemonic Operand(s) ;comment


Optional Opcode name Zero or more Optional
or
Directive name
or
Macro name

Example:
Label Mnemonic
• Equivalent to the address • The name of the operation
of the object code or function of the
generated for the loaded assembly language
instruction statement
• Used as an address or as • The symbolic name
data in another associated with an opcode
instruction’s address field
• The assembler replaces
the label with the
assigned value
Operand(s)
• Each operand identifies an immediate value, a register
value, or a memory location
• Three types of operand references
• Register addressing  Refers to the name of the register
that is used in the instruction
• Immediate addressing  Indicates that the value is
encoded in the instruction
• Direct addressing  Refers to a memory location and is
expressed as a displacement from the DS register
Comment
• Occur at the right-hand
end of statement or can
occupy an entire text line
• It begins with a special
character that signals to
the assembler - to be
ignored by the assembler
• Use a semicolon (;)
Type of Assembly Language Statements

Instruction

Comment Type Directive

Macro
definition
Instructions

• The bulk of statements that are symbolic


representations of machine language instructions.
• The assembler resolves any symbolic references
and translates the assembly language instruction
into the binary string
Directives

• An assembly language statements that are not


directly translated into machine language
instructions.
• Directives are instruction to the assembler to
perform specified actions doing the assembly
process

 Define constants
 Designate areas of memory for data storage
Examples:  Initialize areas of memory
 Place tables or other fixed data in memory
 Allow references to other programs
Macro Definitions

• A section of code that the programmer writes


once, and then can use many times.
• When the assembler encounters a macro call, it
replaces the macro call with the macro itself →
macro expansion.
• Advantage: Same advantage as subroutines in
modular programming.
• Disadvantage: Uses more space in the object
code.

You might also like