Unit 3 JSPSingh
Unit 3 JSPSingh
´ Stack Organization
´ Instruction formats
´ Addressing Modes
Introduction Control
Arithmetic
logic Unit
(ALU)
´ Part of computer that perform bulk of data processing operations – CPU
User who programs the computer in machine or assembly language must be aware
of the register set, the memory structure, the type of data supported by the
instructions and the function that each instruction performs
How registers communicate with ALU through buses and operation of memory stacks
Types of instruction formats, the addressing modes used to retrieve data from memory
and typical instructions commonly incorporated in computers
Major Components of CPU
´ Storage Components
´ Registers
´ Flags
´ Execution (Processing) Components
´ Arithmetic Logic Unit(ALU)
´ Arithmetic calculations, Logical computations, Shifts/Rotates
´ Transfer Components
´ Bus
´ Control Components
´ Control Unit
Register
´ Important:
´ How many registers will be the best ?
General Register Organization
Input
Clock
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA { MUX MUX } SELB
3x8
A bus B bus
decoder
SELD
OPR ALU
Output
Operation of Control Unit
´ The control unit
´ Directs the information flow through ALU by
´ Selecting various Components in the system
3 3 3 5
´ Selecting the Function of ALU SELA SELB SELD OPR
Control Word
´ Example: 𝑹𝟏 ← 𝑹𝟐 + 𝑹𝟑
´ [1] MUX A selector (𝑆𝐸𝐿𝐴): 𝐵𝑈𝑆 𝐴 ← 𝑅2
´ [2] MUX B selector (𝑆𝐸𝐿𝐵): 𝐵𝑈𝑆 𝐵 ← 𝑅3
´ [3] ALU operation selector (OPR): ALU to ADD (A+B)
´ [4] Decoder destination selector (𝑆𝐸𝐿𝐷): 𝑅1 ← 𝑂𝑢𝑡 𝐵𝑢𝑠
Control Word
3 3 3 5
´ Stack Organization
´ Instruction formats
´ Addressing Modes
FULL EMPTY
´ PUSH ´ POP
𝑆𝑃 ← 𝑆𝑃 + 1 Increment SP 𝐷𝑅 ← 𝑀[𝑆𝑃] Read item from top of stack
𝑀 𝑆𝑃 ← 𝐷𝑅 Write item on top of Stack 𝑆𝑃 ← 𝑆𝑃 − 1 Decrement SP
𝐼𝑓 𝑆𝑃 = 0 𝑡ℎ𝑒𝑛 𝐹𝑈𝐿𝐿 ← 1 Check if stack is full 𝐼𝑓 𝑆𝑃 = 0 𝑡ℎ𝑒𝑛 𝐸𝑀𝑇𝑌 ← 1 Check if stack is empty
𝐸𝑀𝑇𝑌 ← 0 Mark stack not empty 𝐹𝑈𝐿𝐿 ← 0 Mark the stack not full
Memory Stack Organization
1000
𝐴∗𝐵+𝐶∗𝐷
´ Example
´ 𝐴+𝐵 Infix notation
´ +𝐴𝐵 Prefix or Polish Notation
´ 𝐴𝐵 + Postfix or Reverse Polish Notation (RPN)
Reverse Polish Notation is very suitable for stack manipulation
Reverse Polish Notation …
𝐴∗𝐵+𝐶∗𝐷
𝐴𝐵 ∗ 𝐶𝐷 ∗ +
´ First Inner parenthesis followed outer parenthesis
´ Multiplication and division operation before addition and subtraction
𝐴 + 𝐵 ∗ [𝐶 ∗ 𝐷 + 𝐸 + 𝐹]
𝐴𝐵 + 𝐷𝐸 + 𝐶 ∗ 𝐹 +∗
Evaluation of Arithmetic Expressions
3∗4 + 5∗6
´ In Reverse Polish notation
34 ∗ 56 ∗ +
´ Stack Operations Top of Stack
6
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
Content
´ Introduction
´ Stack Organization
´ Instruction formats
´ Addressing Modes
´ Instruction Fields
𝐴𝐷𝐷 𝑋
´ 𝐴𝐶 ← 𝐴𝐶 + 𝑀[𝑋]
Processor Organization
General register organization
´ Generally requires three register address field
Example:
𝐴𝐷𝐷 𝑅1, 𝑅2
´ 𝑅1 ← 𝑅1 + 𝑅2
Processor Organization
General register organization
´ One register and other as memory address
Example:
𝐴𝐷𝐷 𝑅1, 𝑋
´ 𝑅1 ← 𝑅1 + 𝑀[𝑋]
´ Move instruction
Example:
𝑀𝑂𝑉 𝑅1, 𝑅2
´ 𝑅1 ← 𝑅2 or 𝑅2 ← 𝑅1 (depends on particular computer)
Processor Organization
Stack organization
´ Would use PUSH and POP instruction with address field
Example:
𝑃𝑈𝑆𝐻 𝑋
𝑇𝑂𝑆 ← 𝑀[𝑋]
𝐴𝐷𝐷
Three Address Instructions
𝑋 = 𝐴+𝐵 ∗ 𝐶+𝐷
𝑋 = 𝐴+𝐵 ∗ 𝐶+𝐷
´ 𝑀𝑂𝑉 𝑅1, 𝐴 𝑅1 ← 𝑀 𝐴
´ 𝐴𝐷𝐷 𝑅1, 𝐵 𝑅1 ← 𝑅1 + 𝑀 𝐵
´ 𝑀𝑂𝑉 𝑅2, 𝐶 𝑅2 ← 𝑀 𝐶
´ 𝐴𝐷𝐷 𝑅2, 𝐷 𝑅2 ← 𝑅2 + 𝑀 𝐷
´ 𝑀𝑈𝐿 𝑅1, 𝑅2 𝑅1 ← 𝑅1 ∗ 𝑅2
´ 𝑀𝑂𝑉 𝑋, 𝑅1 𝑀[𝑋] ← 𝑅1
One Address Instructions
𝑋 = 𝐴+𝐵 ∗ 𝐶+𝐷
´ 𝐿𝑂𝐴𝐷 𝐴 𝐴𝐶 ← 𝑀 𝐴
´ 𝐴𝐷𝐷 𝐵 𝐴𝐶 ← 𝐴𝐶 + 𝑀 𝐵
´ 𝑆𝑇𝑂𝑅𝐸 𝑇 𝑀[𝑇] ← 𝐴𝐶
´ 𝐿𝑂𝐴𝐷 𝐶 𝐴𝐶 ← 𝑀 𝐶
´ 𝐴𝐷𝐷 𝐷 𝐴𝐶 ← 𝐴𝐶 + 𝑀 𝐷
´ 𝑀𝑈𝐿 𝑇 𝐴𝐶 ← 𝐴𝐶 ∗ 𝑀[𝑇]
´ 𝑆𝑇𝑂𝑅𝐸 𝑋 𝑀[𝑋] ← 𝐴𝐶
Zero Address Instructions
𝑋 = 𝐴+𝐵 ∗ 𝐶+𝐷
´ 𝑃𝑈𝑆𝐻 𝐴 𝑇𝑂𝑆 ← 𝐴
´ 𝑃𝑈𝑆𝐻 𝐵 𝑇𝑂𝑆 ← 𝐵
´ 𝐴𝐷𝐷 𝑇𝑂𝑆 ← (𝐴 + 𝐵)
´ 𝑃𝑈𝑆𝐻 𝐶 𝑇𝑂𝑆 ← 𝐶
´ 𝑃𝑈𝑆𝐻 𝐷 𝑇𝑂𝑆 ← 𝐷
´ 𝐴𝐷𝐷 𝑇𝑂𝑆 ← (𝐶 + 𝐷)
´ 𝑀𝑈𝐿 𝑇𝑂𝑆 ← 𝐶 + 𝐷 ∗ 𝐴 + 𝐵
´ 𝑃𝑂𝑃 𝑋 𝑀[𝑋] ← 𝑇𝑂𝑆
Content
´ Introduction
´ Stack Organization
´ Instruction formats
´ Addressing Modes
´ EA = BAR + IR(address)
Example – Addressing Mode Address Memory
´ Direct Address AC
´ Immediate Operand 500 800
´ Indirect Address
´ Relative Address 600 900
´ Indexed Address
´ Register 702 325
´ Register Indirect
´ Autoincrement 800 300
´ Auto decrement
Example – Addressing Mode Address Memory
399 450
XR = 100
400 700
´ Stack Organization
´ Instruction formats
´ Addressing Modes
Name Mnemonic
Load LD
Store ST Data Transfer Instructions with Different Addressing Modes
Move MOV
Exchange XCH Assembly
Input IN Mode Convention Register Transfer
Output OUT Direct address LD ADR AC ¬ M[ADR]
Push PUSH Indirect address LD @ADR AC ¬ M[M[ADR]]
Pop POP Relative address LD $ADR AC ¬ M[PC + ADR]
Immediate operand LD #NBR AC ¬ NBR
Index addressing LD ADR(X) AC ¬ M[ADR + XR]
Register LD R1 AC ¬ R1
Register indirect LD (R1) AC ¬ M[R1]
Autoincrement LD (R1)+ AC ¬ M[R1], R1 ¬ R1 + 1
Autodecrement LD -(R1) R1 ¬ R1 - 1, AC ¬ M[R1]
Data Manipulation Instructions
´ Performs arithmetic, logic and shift operations
´ Three basic types
´ Arithmetic instructions
´ Logical and bit manipulation instructions
´ Shift instructions
´ Stack Organization
´ Instruction formats
´ Addressing Modes
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Call CALL
Return RTN
Compare(by Subtraction- ) CMP
Test(by AND) TST * CMP and TST instructions do not retain their
results of operations ( - and AND, resp.).
They only set or clear certain Flags.
Flag, Processor Status Word
´ In Basic Computer, the processor had several (status) flags – 1 bit value that
indicated various information about the processor’s state – E, FGI, FGO, I,
IEN, R
´ In some processors, flags like these are often combined into a register – the
Processor Status Register (PSR); sometimes called a Processor Status Word
(PSW)
´ Common flags in PSW are
Status Flag Circuit
´ C (Carry): Set to 1 if the carry out of the ALU is 1
A B
´ S (Sign): The MSB bit of the ALU’s output (F7) 8 8
c7
´ Z (Zero): Set to 1 if the ALU’s output is all 0’s
8-bit ALU
c8
´ V (Overflow): Set to 1 if there is an overflow F7 - F0
V Z S C
F7
Check for 8
zero output
F
Conditional Branch Instruction
Mnemonic Branch condition Tested condition
BZ Branch if zero Z=1
BNZ Branch if not zero Z=0
BC Branch if carry C=1
BNC Branch if no carry C=0
BP Branch if plus S=0
BM Branch if minus S=1
BV Branch if overflow V=1
BNV Branch if no overflow V=0
Many ways of saving the CPU state depending on the CPU architectures
Content
´ Introduction
´ Stack Organization
´ Instruction formats
´ Addressing Modes
´ More than 100 and sometimes even more than 200 instructions
´ Employ a variety of data types and larges number of addressing modes
´ Large Number of Instructions – Complex Instruction Set Computer (CISC)
´ Early computers (1980s) had small and simple instruction sets – Minimize the
hardware used to implement them
´ Fewer instructions – Simple constructions – Execution is much faster
´ Limit the use of memory – Reduced Instruction Set Computer (RISC)
RISC – Historical Background
IBM System/360, 1964
´ The real beginning of modern computer architecture
´ Distinction between Architecture and Implementation
´ Architecture: The abstract structure of a computer seen by an assembly-language
programmer
Hardware
µ-program
Compiler
High-Level Instruction Hardware
Language Set
Architecture
Hardware
Implementation
CISC
´ These computers with many instructions and addressing modes came to be
known as Complex Instruction Set Computers (CISC)
´ One goal for CISC machines was to have a machine language instruction
to match each high-level language statement type
Complex Instruction Set Computers
´ Another characteristic of CISC computers is that they have instructions that act directly on
memory addresses
For example,
ADD L1, L2, L3
that takes the contents of M[L2] adds it to the contents of M[L3] and stores the result in
location M[L1]
´ An instruction like this takes three memory access cycles to execute
´ makes for a potentially very long instruction execution cycle
´ The problems with CISC computers are
´ The complexity of the design may slow down the processor,
´ The complexity of the design may result in costly errors in the processor design and implementation
´ Many of the instructions and addressing modes are used rarely, if ever
Summary: Criticism on CISC
High Performance General Purpose Instructions
´ Complex Instruction
´ Format, Length, Addressing Modes
´ Complicated instruction cycle control due to the complex decoding HW and decoding process
´ Multiple memory cycle instructions
´ Operations on memory data
´ Multiple memory accesses/instruction
´ Microprogrammed control is necessity
´ Microprogram control storage takes substantial portion of CPU chip area
´ Semantic Gap is large between machine instruction and microinstruction
´ General purpose instruction set includes all the features required by individually different
applications
´ When any one application is running, all the features required by the other applications are extra
burden to the application
RISC – Reduced Instruction Set Computers
´ In the late ‘70s and early ‘80s there was a reaction to the shortcomings of the CISC style of
processors
´ Reduced Instruction Set Computers (RISC) were proposed as an alternative
´ The underlying idea behind RISC processors is to simplify the instruction set and reduce
instruction execution time
´ RISC processors often feature:
´ Few instructions
´ Few addressing modes
´ Only load and store instructions access memory
´ All other operations are done using on-processor registers
´ Fixed length instructions
´ Single cycle execution of instructions
´ The control unit is hardwired, not microprogrammed
RISC – Reduced Instruction Set Computers
´ Since all but the load and store instructions use only registers for operands, only
a few addressing modes are needed
´ By having all instructions the same length, reading them in is easy and fast
´ The fetch and decode stages are simple
´ The instruction and address formats are designed to be easy to decode
´ Unlike the variable length CISC instructions, the opcode and register fields of
RISC instructions can be decoded simultaneously
´ The control logic of a RISC processor is designed to be simple and fast
´ The control logic is simple because of the small number of instructions and the
simple addressing modes
´ The control logic is hardwired, rather than microprogrammed, because
hardwired control is faster