Professional Documents
Culture Documents
Chapter 2 (AutoSaved)
Chapter 2 (AutoSaved)
Chapter 2 (AutoSaved)
2
Instruction Set Characteristics & Function
• The operation of the processor is determined by the instructions it executes, referred
to as machine instructions or computer instructions.
• The collection of different instructions that the processor can execute is referred to
as the processor’s instruction set.
Elements of a Machine Instruction
• Each instruction must contain the information required by the processor for execution.
• Operation code: Specifies the operation to be performed (e.g., ADD, I/O). The operation is
specified by a binary code, known as the operation code, or opcode.
• Source operand reference: The operation may involve one or more source operands, that is,
operands that are inputs for the operation.
• Result operand reference: The operation may produce a result.
• Next instruction reference: This tells the processor where to fetch the next instruction after the
execution of this instruction is complete.
3
Instruction set Architecture & Characteristics
• The address of the next instruction to be fetched could be either a real address or a virtual address, depending on
the architecture.
Source and Result operands can be found in one of the four areas:
Main or Virtual Memory, Processor Register,
• Immediate: The value of the operand is contained in a field in the instruction being executed.
• I/O device: The instruction must specify the I/O module and device for the operation. If memory-mapped I/O is
used, this is just another main or virtual memory address.
Instruction Representation
5
Instruction set Architecture & Characteristics
Instruction Representation(Cont..)
• Within the computer, each instruction is represented by a sequence of bits.
• The instruction is divided into fields, corresponding to the constituent elements of the instruction.
• During instruction execution, an instruction is read into an instruction register (IR) in the processor.
• The processor must be able to extract the data from the various instruction fields to perform the required
operation.
• Since it is difficult to deal with the binary representation of machine instructions, it become common practice to
use Symbolic representation of machine instructions.
• Opcodes are represented by abbreviations, called mnemonics, that indicate the operation.
Examples are
6
Instruction Representation(Cont..)
ADD R, Y
Means add the value contained in data location Y to the contents of register R.
Note that the operation is performed on the contents of a location, not on its address.
Instruction Types
• the set of machine instructions must be sufficient to express any of the instructions from a high-level language.
Data Processing
7
Instruction Types
Categories of Instruction Types…
Data processing
Arithmetic and logic instructions
Data Storage
Memory Instructions
Data Movement
I/O Instructions
Control
Test and Branch Instructions
8
Instruction Set Design
• One of the most interesting, and most analyzed, aspects of computer design
Operation Repertoire: How many ops, what can they do and how complex they are
Data types: various types of data upon which operations are performed
Instruction format: Instruction length (in bits), number of addresses, size of various fields, and so on
Registers: Number of processor registers that can be referenced by instructions, and their use.
Numbers
Characters
Boolean
Bits or flags
10
Types of Operations
• A useful and typical categorization is the following:
Data transfer
Arithmetic
Logical
Conversion
I/O
System control
Transfer of control
11
Data Transfer
Most fundamental type of instructions
Must specify the following things
Location of source and destination operands
memory, register …
Length of data to be transferred
Full word, half word …
Addressing mode of each operand
E.g.
Move, Store, Load, Push, Pop
In terms of CPU action
data transfer operations are the simplest type
12
Arithmetic
Performed by ALU
Basic arithmetic operations provided by most
• machines are:
Add, Subtract, Multiply, Divide
Signed Integer
Floating point
May include
Increment
Decrement
Negate
Absolute
13
Logical
Operations that manipulate individual bits of a word
Bitwise operations
AND, OR, exclusive-OR (XOR)
NOT (one’s complement)
In addition a variety of shifting and rotating functions
Logical shift
Shifts bits of word either to the left or right
On one end the bit shifted out is lost
Arithmetic shift
Treats the data as a signed integer and does not shift the sign bit
Rotate/Cyclic shift
Preserves all of the bits being operated on
14
SHIFT AND ROTATE OPERATIONS
0
logical
shift
shift in 0
arithme
tic
shift
keep sign !
rotate
15
Conversion
Change the format of data or operate on the format of data
Binary to Decimal
ASCII to EBCDIC
16
Input/Output
Transfer data
from the computer to peripheral devices
From peripheral devices to the computer system
To be seen in detail in another chapter
17
System Control
Reserved for use by the operating system
Instructions executed while the processor is in certain privileged
mode
Privileged instructions
CPU needs to be in specific state
18
Transfer of Control
Alter the flow of program
i.e. change the sequence of instruction execution
Update the PC to a specific address
Most common such type of operations are:
Branch, Skip, Procedure call
19
Transfer of Control
Branch
Also called jump instruction
Its operand is the address of the next instruction to be fetched and executed
Two types of branches
Conditional and Unconditional
Conditional Branch
A branch is made if certain condition is met
E.g.
BRP X
Branch to instruction at location X if result is positive
BRZ X
Branch to instruction at location X if result is zero
BRE R1,R2,X
Branch to X if contents of R1 is equal to contents of R2
20
Transfer of Control
Unconditional branch
E.g.
BR X
Branch to instruction at location X
Branch Instructions
21
Transfer of Control
Skip
Implies that the next instruction be skipped
Contains an implied address
Can be of two types:
Unconditional
Skip (i.e. unconditionally increment PC to skip the next instruction)
Conditional
• Notations:
• A = Contents of an address field in the instruction
• R = Contents of an address field in the instruction that refers to a register
• (X) = Contents of memory location X or register X
• EA =Effective address of the location containing the referenced operand
23
Addressing Modes
Types of addressing modes
Immediate
Direct
Indirect
Register
Register Indirect
Displacement
Stack
24
Immediate Addressing Mode
The instruction itself contains the operands value
Operand is part of instruction
Operand = A
E.g. ADD 5
Add 5 to contents of accumulator
5 is operand
25
Immediate Addressing Mode
Opcode Operand
26
Direct Addressing
Address field contains address of operand
Effective address EA = A
Operand = (A)
E.g. ADD A
Add contents of memory location A to accumulator
One more memory access needed to fetch the operand
No additional calculations required to work out effective address
• Number of Memory locations that can be referenced are limited, due to the limited width of the
field.
Limited address space
• Common on earlier generation of computers
27
Direct Addressing Diagram
28
Indirect Addressing
A (the address field) refers to a memory location which contains the
address of operand
Multiple (two) memory accesses to find operand
Fetch EA
Fetch operand
Access the memory twice, hence slower
EA = (A)
Operand = ((A))
E.g. ADD (A)
Look in A, find address (A) and look there for operand
Range of EA increased
Large address space
2n ,where n = word length
29
Indirect Addressing Diagram
30
Register Addressing
Similar to direct addressing
The address field refers to a register than a main memory address
EA = R
Operand = (R )
Very small address field needed
Shorter instructions
Faster instruction fetch
No memory access required
Very fast execution
Very limited address space
Small number of registers can be referenced
31
Register Addressing Diagram
32
Register Indirect Addressing
Similar to indirect addressing mode
Operand is in memory pointed to by contents of register R
EA = (R)
Operand =((R ))
33
Register Indirect Addressing Diagram
34
Displacement Addressing
Very powerful addressing mode
Combines
direct addressing and
Register indirect addressing
Instruction needs to have two address fields
At least one of which is explicit
EA = A + (R)
Address field hold two values
A = base value
R = register that holds displacement
or vice versa
35
Displacement Addressing Diagram
36
Relative Addressing
A version of displacement addressing mode
Implicitly references the PC register
R = Program counter, PC
EA = A + (PC)
Saves bits
37
Base Register Addressing
Referenced register contains memory address
R holds pointer to base address
38
Indexed Addressing
Address field contains memory address
A = base
The referenced register contains a displacement from that address
R = displacement
EA = A + ( R )
Good for accessing arrays and performing iterative operations.
Auto Indexing
Increment and Decrement
Read Computer Architecture & Organization[Author William
Stallings, page 412
39
Indexed Addressing
Combinations
Indirect addressing with indexing
Post indexing
The indexing performed after the indirection
• EA = (A) + (R)
Good to access a block of data of a fixed format
Pre indexing
The indexing performed before the indirection
• EA = (A+(R))
Used to construct a multiway branch table
40
STACK ADDRESSING
A stack
The stack mode of addressing is a form of implied
addressing
The machine instructions need not include a memory
reference but implicitly operate on the top of the
stack
41
INSTRUCTION FORMAT
It defines the layout of the bits of an instruction,
in terms of its constituent parts
42
3.4 INSTRUCTION CYCLE REVISITED
Instruction cycle so far consists of the
following sub cycles:
Fetch
Execute
Interrupt
43
INSTRUCTION CYCLE ,REVISED …
Indirect addressing
May require memory access to fetch operands
Indirect addressing requires more memory accesses
Can be thought of as additional instruction subcycle
44
3.5 INSTRUCTION CYCLE DATA FLOW
The exact sequence of events during an
instruction cycle depends on the design of the
CPU
46
DATA FLOW (FETCH DIAGRAM)
47
DATA FLOW (DATA FETCH)
IR is examined
If indirect addressing, indirect cycle is performed
Right most N bits of MBR transferred to MAR
Control unit requests memory read
Result (address of operand) moved to MBR
48
DATA FLOW (INDIRECT DIAGRAM)
49
DATA FLOW (EXECUTE)
May take many forms
Depends on instruction being executed
May include
Memory read/write
Input/Output
Register transfers
ALU operations
50
DATA FLOW (INTERRUPT)
Simple and Predictable
Current PC saved to resumption after
allow interrupt
Contents of PC copied to MBR
Special memory location (e.g. stack
pointer) loaded to MAR
MBR written to memory
PC loaded with address of interrupt
handling routine
Next instruction (first of interrupt handler)
can
be fetched 51
DATA FLOW (INTERRUPT DIAGRAM)
52
3.6 PROCESSOR STRUCTURE AND
FUNCTION
Processor Organization
To understand the organization of the CPU,
recall the requirements placed on the CPU:
Fetch instruction
Interpret instruction
Fetch data
Process data
Write data
54
PROCESSOR ORGANIZATION…
Detailed view of a CPU
Indicates
Data transfer and logic control paths
Internal processor bus
55
Bus Organization for CPU Registers
R1
R2
R3
R4
R5
R6
R7
3x8 A B
Decoder
OPR
ALU
SELD
56
Bus Organization for 7 CPU Registers
• 2 MUX : select one of 7 register or external data input by SELA and SELB
• BUS A and BUS B : form the inputs to a common ALU
• 3 X 8 Decoder : select the register (by SELD) that receives the information from ALU
57
Bus Organization for 7 CPU Registers
• Binary selector input : R1 R 2 R3
• 1) MUX A selector (SELA) : to place the content of R2 into BUS A
• 2) MUX B selector (SELB) : to place the content of R3 into BUS B
• 3) ALU operation selector (OPR) : to provide the arithmetic addition R2 + R3
• 4) Decoder selector (SELD) : to transfer the content of the output bus into R1
• Control Word
• 14 bit control word (4 fields) :
• SELA (3 bits) : select a source register for the A input of the ALU
• SELB (3 bits) : select a source register for the B input of the ALU
• SELD (3 bits) : select a destination register using the 3 X 8 decoder
• OPR (5 bits) : select one of the operations in the ALU
• Encoding of Register Selection Fields :
• SELA or SELB = 000 (Input) : MUX selects the external input data
• SELD = 000 (None) : no destination register is selected but the contents of the output bus are available in the external
output
• Encoding of ALU Operation (OPR) :
59
REGISTER ORGANIZATION
Registers
CPU must have some working space
Temporary storage
Top level of memory hierarchy
Number and function vary between processor designs
One of the major design decisions
60
REGISTER ORGANIZATION…
Registers classified into two groups:
User visible registers:
Can be referenced by assembly language instructions
61
USER VISIBLE REGISTERS
Can be categorized as follows:
General purpose registers
Data registers
Address registers
Condition codes
62
USER VISIBLE REGISTERS…
General Purpose Registers
Can be assigned variety of function by
the
programmer
May be true general purpose
May be restricted
May be used for data or addressing
Data Registers
Used only to hold data
Accumulator
63
USER VISIBLE REGISTERS…
Address registers
Hold addresses
Can be
General purpose or
Devoted to particular addressing mode
64
CONDITION CODES
Sets of individual bits , also called flags
Each bit set by CPU hardware as the result
of
operations:
E.g. Arithmetic operation results could be
Positive, negative, zero, overflow
Can be read (implicitly) by programs
e.g. Jump if zero
Can not (usually) be set by programs
65
CONTROL & STATUS REGISTERS
Refers to different registers employed to
control the operation of the CPU
Most not visible to the user
66
CONTROL & STATUS REGISTERS…
Program Status Word (PSW)
A register that contain status information
Usually contains
Condition codes
Status information
Common fields or flags include
Sign, zero, carry, equal, overflow, interrupt
supervisor, enable/disable