Professional Documents
Culture Documents
Lecture 22
Overview
Introduction
General Register Organization
Stack Organization
Instruction Formats
Addressing Modes
Data Transfer and Manipulation
Program Control and Program Interrupt
CSE 211, Computer Organization and Architecture
Storage Components
Registers
Flags
Transfer Components
Bus
Control Components
Control Unit
Register
Clock
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA
3x8
decoder
MUX
MUX
A bus
SELD
OPR
B bus
ALU
Output
}SELB
Operation of ControlUnit
3
SELA
3
SELB
3
SELD
5
OPR
Binary
Code
000
001
010
011
100
101
110
111
SELA
Input
R1
R2
R3
R4
R5
R6
R7
SELB
Input
R1
R2
R3
R4
R5
R6
R7
SELD
None
R1
R2
R3
R4
R5
R6
R7
ALU Control
OPR
Select
00000
00001
00010
00101
00110
01000
01010
01100
01110
10000
11000
Operation
Symbol
Transfer A
TSFA
Increment A
INCA
ADD A + B
ADD
Subtract A - B SUB
Decrement A DECA
AND A and B AND
OR A and B
OR
XOR A and B XOR
Complement A COMA
Shift right A
SHRA
Shift left A
SHLA
SELD OPR
R2
R4
R3
R5
R6
R1
R2
Input
R4
R5
R5
R1
R4
Control Word
SUB
OR
Stack Organization
Stack
Very useful feature for nested subroutines, nested
interrupt services
Also efficient for arithmetic expression evaluation
Storage which can be accessed in LIFO
Pointer: SP
Only PUSH and POP operations are applicable
Stack Organization
Register Stack Organization
Memory Stack Organization
Flags
FULL
EMPTY
Stack pointer
SP
C
B
A
6 bits
DR
PUSH
SP
SP + 1
M[SP]
DR
If (SP = 0) then (FULL
EMPTY
0
POP
1)
DR
M[SP]
SP
SP 1
If (SP = 0) then (EMPTY
FULL
0
1)
4
3
2
1
0
PC
Program
(instructions)
AR
Data
(operands)
SP
3000
stack
3997
3998
3999
4000
4001
SP SP - 1
M[SP] DR
- POP: DR M[SP]
SP SPdo
+1
- Most computers
not provide hardware to check stack
overflow (full
stack) or underflow (empty stack) must be done in
CSE 211, Computer Organization and Architecture
- PUSH:
10
Arithmetic Expressions: A + B
A + B Infix notation
+ A B Prefix or Polish notation
A B + Postfix or reverse Polish notation
- The reverse Polish notation is very suitable for
stack manipulation
4
3
12
5
12
34*56*+
6
5
12
30
12
42
11
Processor Organization
Stack organization
All operations are done using the hardware stack
CSE 211, Computer Organization and Architecture
12
Instruction Format
Instruction Fields
OP-code field - specifies the operation to be performed
Address field - designates memory address(es) or a processor
register(s)
Mode field
- determines how the address field is to be
interpreted (to
get
effective
address
or the
operand) format
The number of
address
fields
in the
instruction
13
Three-Address Instructions
*/
*/
*/
Program to evaluate X = (A + B) * (C + D) :
ADD R1, A, B
/*
R1 M[A] + M[B]
ADD R2, C, D
MUL X, R1, R2 /*
/*
R2 M[C] + M[D]
M[X] R1 * R2
Two-Address Instructions
Program to evaluate X = (A + B) * (C + D) :
MOV R1, A
/* R1 M[A]
ADD
R1, B
/* R1 R1 + M[B]
MOV R2, C
/* R2 M[C]
ADD
R2, D
/* R2 R2 + M[D]
MUL
R1, R2
/* R1 R1 * R2
MOV
X, R1
/* M[X] R1
CSE 211, Computer Organization and Architecture
*/
*/
*/
*/
*/
*/
14
One-Address Instructions
15
Zero-Address Instructions
- Can be found in a stack-organized computer
- Program to evaluate X = (A + B) * (C + D) :
PUSH A
PUSH B
ADD
PUSH C
PUSH D
ADD
MUL
+ B) */
POP
X
/*
/*
/*
/*
/*
/*
/*
/*
TOS A */
TOS B */
TOS (A + B) */
TOS C */
TOS D */
TOS (C + D) */
TOS (C + D) * (A
M[X] TOS*/
16
Addressing Mode
Addressing Modes
- Specifies a rule for interpreting or modifying the address
field of the
instruction (before the operand is actually
referenced)
- Variety of addressing modes
- to give programming flexibility to the user
- toMode
use the bits in the address field of the
1. Implied
instruction
efficiently
- Address
of the operands are specified implicitly in the
definition of the instruction
- No need to specify address in the instruction
- EA = AC, or EA = Stack[SP]
- Examples from Basic Computer - CLA, CME, INP
2. Immediate Mode
- Instead of specifying the address of the operand, operand
itself is specified
- No need to specify address in the instruction
- However, operand itself needs to be specified
- Sometimes, require more bits than the address
- Fast to acquire an operand
CSE 211, Computer Organization and Architecture
17
Addressing Mode
3. Register Mode
- Address specified in the instruction is the register
address
- Designated operand need to be in a register
- Shorter address than the memory address
- Saving address field in the instruction
- Faster to acquire an operand than the memory
addressing
- EA = IR(R) (IR(R): Register field of IR)
18
Addressing Mode
19
Addressing Mode
20
200
201
202
Memory
Load to AC
Address = 500
Next instruction
399
400
450
700
500
800
600
900
702
325
800
300
AC
Addressing
Effective
Mode
Address
Direct address
500
Immediate operand Indirect address
800
Relative address
702
Indexed address
600
Register
Register indirect
400
Autoincrement
400
Autodecrement
399
/* AC (500)
/* AC 500
/* AC ((500))
/* AC (PC+500)
/* AC (RX+500)
/* AC R1
/* AC (R1)
/* AC (R1)+
/* AC -(R)
*/
*/
*/
*/
*/
*/
*/
*/
*/
Content
of AC
800
500
300
325
900
400
700
700
450
Mode
21
Mnemonic
LD
ST
MOV
XCH
IN
OUT
PUSH
POP
22
23
24
Arithmetic Instructions
Name
Increment
Decrement
Add
Subtract
Multiply
Divide
Add with Carry
Subtract with Borrow
Negate(2s Complement)
Mnemonic
INC
DEC
ADD
SUB
MUL
DIV
ADDC
SUBB
NEG
25
Mnemonic
Clear
CLR
Complement
COM
AND
AND
OR
OR
Exclusive-OR
XOR
Clear carry
CLRC
Set carry
SETC
Complement carry
COMC
Enable interrupt
EI
Disable interrupt
DI
26
Shift Instructions
Name
Mnemonic
27
PC
+1
In-Line Sequencing (Next instruction is
fetched from the next adjacent location in
the memory)
Mnemonic
BR
JMP
SKP
CALL
RTN
CMP
TST* CMP and TST instructions do not
retain their
results of operations ( and AND,
resp.).
They only set or clear certain
28
Branch condition
Branch
Branch
Branch
Branch
Branch
Branch
Branch
Branch
if
if
if
if
if
if
if
if
zero
not zero
carry
no carry
plus
minus
overflow
no overflow
Tested condition
Z=1
Z=0
C=1
C=0
S=0
S=1
V=1
V=0
29
Subroutine Call
Call subroutine
Jump to subroutine
Branch to subroutine
Branch and save return address
CALL
RTN
SP SP - 1
M[SP] PC
PC EA
PC M[SP]
SP SP + 1
30
C (Carry): Set to 1 if the carry out of the ALU is 1Status Flag Circuit
S (Sign): The MSB bit of the ALUs output
A
B
8
8
Z (Zero): Set to 1 if the ALUs output is all 0s
c7
V (Overflow): Set to 1 if there is an overflow
c8
8-bit ALU
F7 - F 0
F7
Check for
zero output
F
CSE 211, Computer Organization and Architecture
31
Program Interrupt
Types of Interrupts
External interrupts
External Interrupts initiated from the outside of CPU and Memory
- I/O Device Data transfer request or Data transfer complete
- Timing Device Timeout
- Power Failure
- Operator
Internal interrupts (traps)
Internal Interrupts are caused by the currently running program
- Register, Stack Overflow
- Divide by zero
- OP-code Violation
- Protection Violation
Software Interrupts
Both External and Internal Interrupts are initiated by the computer HW.
Software Interrupts are initiated by the executing an instruction.
- Supervisor Call
1. Switching from a user mode to the supervisor mode
2. Allows to execute a certain class of operations
which are not allowed in the user mode
32
Interrupt Procedure
33
-program
Compiler
High-Level
Instruction
Hardware
Language
Set
Architecture
Hardware
Implementation
34
CISC
CISC
35
36
37
CSE 211,
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
Computer Organization and Architecture
38
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