CH 8
CH 8
CH 8
Introduction
n
1 / 22
3 / 22
8-1 Introduction
u 3 major parts of CPU : Fig. 8-1 l 1) Register Set l 2) ALU l 3) Control u Design Examples of simple CPU l Hardwired Control : Chap. 5 l Microprogrammed Control : Chap. 7
Computer Architecture as seen by the programmer u In this chapter : Chap. 8 l Describe the organization and architecture of the CPU with an emphasis on the user view of the computer s l User who programs the computer in machine/assembly language must be aware of 1) Instruction Formats 2) Addressing Modes 3) Register Sets
l
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
Chap. 8
The last section presents the concept of Reduced Instruction Set Computer (RISC)
Chap. 8 Central Processing Unit
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 Control Word Control Memory l Encoding of ALU Operation (OPR) : Tab. 8-2 Microprogrammed Control u Examples of Microoperations : Tab. 8-3
l l
TSFA (Transfer A) : R 7 R1, External Output R 2, External Output External Input XOR : R5 0 ( XOR R5 R 5)
Chap. 8 Central Processing Unit
2 / 22
4 / 22
Input
MUX B bus
SELB
l
Stack
1) Register Stack (Stack Depth )
n
3 X 8 Decoder : select the register (by SELD) that receives the information from ALU
Chap. 8 Central Processing Unit
SP
Last Item
C B A
EMTY 0
DR
5 / 22
7 / 22
POP : DR M [ SP ]
SP SP 1
: Decrement Stack Pointer If ( SP = 0 ) then ( EMTY 1) : Check if stack is empty FULL 0 : Mark not full
PC
* Memory Stack PUSH = Address * Register Stack PUSH = Address Address Memory unit 1000 Program (instructions) 2000 Data (operands) 3000 Stack 3997 3998 3999 4000 4001
u The influence of the number of addresses on computer instruction [] X = (A + B)*(C + D) - 4 arithmetic operations : ADD, SUB, MUL, DIV - 1 transfer operation to and from memory and general register : MOV - 2 transfer operation to and from memory and AC register : STORE, LOAD - Operand memory addresses : A, B, C, D - Result memory address : X l 1) Three-Address Instruction
ADD ADD MUL R1, A, B R2, C, D X, R1, R2
M [ SP ] DR
The first item is stored at address 4000
AR
POP : DR M [ SP ]
SP SP + 1
* Error Condition PUSH when FULL = 1 POP when EMTY = 1
SP
R1 M [ A] + M [ B ] R 2 M [C ] + M [ D ] M [ X ] R1 R 2
Upper Limit and Lower Limit Register SP compared with the upper limit register SP compared with the lower limit register Chap. 8 Central Processing Unit
Start Here
DR
Each address fields specify either a processor register or a memory operand : Short program Require too many bit to specify 3 address y
Chap. 8 Central Processing Unit
6 / 22
l
8 / 22
Stack Arithmetic u RPN (Reverse Polish Notation) l The common mathematical method of writing arithmetic expressions imposes difficulties when evaluated by a computer l A stack organization is very effective for evaluating arithmetic expressions l A * B + C * D AB * CD * + : Fig. 8-5 ) ( 3 * 4 ) + ( 5 * 6 ) 34 * 56 * +
R1 M [ A ] R1 R1 + M [ B ] R 2 M [C ] R2 R2 + M [D] R1 R1 R 2 M [ X ] R1
6 4 3 3 3 4 12 * 5 12 5 5 12 6 30 12 * 42 +
l
The most common in commercial computers Each address fields specify either a processor register or a memory operand
3) One-Address Instruction
LOAD ADD STORE LOAD ADD MUL STORE A B T C D T X
AC M [ A] AC A[C ] + M [ B ]
M [T ] AC AC M [C ] AC AC + M [ D ] AC AC M [T ] M [ X ] AC
All operations are done between the AC register and memory operand
9 / 22
11 / 22
4) Zero-Address Instruction
PUSH PUSH ADD PUSH PUSH ADD MUL POP X C D A B
Stack-organized computer does not use an address field for the instructions ADD, and MUL PUSH, and POP instructions need an address field to specify the operand Zero-Address : absence of address ( ADD, MUL )
u RISC Instruction l Only use LOAD and STORE instruction when communicating between memory and CPU l All other instructions are executed within the registers of the CPU without referring to memory l RISC architecture will be explained in Sec. 8-8
Computer System Architecture
u Implied Mode l Operands are specified implicitly in definition of the instruction l Examples
COM : Complement Accumulator
n
Operand in AC is implied in the definition of the instruction Operand is implied to be on top of the stack Chap. 8 Central Processing Unit
10 / 22
12 / 22
Program to evaluate X = ( A + B ) * ( C + D )
LOAD LOAD LOAD LOAD ADD ADD MUL STORE R1, A R2, B R3, C R4, D R1, R1, R2 R3, R3, R4 R1, R1, R3 X, R1
R1 M [ A] R2 M [B] R 3 M [C ] R4 M [D ] R1 R1 + R 2 R3 R3 + R4 R1 R1 R 3 M [ X ] R1
Example : LD R1
AC R1
Implied Mode
u Register Indirect Mode l Selected register contains the address of the operand rather than the operand itself l : Address field of the instruction uses fewer bits to select a memory address
Register select bit
l
u Instruction Cycle l 1) Fetch the instruction from memory and PC + 1 l 2) Decode the instruction l 3) Execute the instruction
Computer System Architecture
Example : LD (R1)
AC M [R1]
u Autoincrement or Autodecrement Mode l Similar to the register indirect mode except that
the register is incremented after its value is used to access memory the register is decrement before its value is used to access memory
Computer System Architecture
13 / 22
15 / 22
AC M [ R1], R1 R1 + 1
u Direct Addressing Mode l Effective address is equal to the address field of the instruction (Operand) l Address field specifies the actual branch address in a branch-type instruction AC M [ ADR ] l Example : LD ADR u Indirect Addressing Mode l Address field of instruction gives the address where the effective address is stored in memory AC M [ M [ ADR ]] l Example : LD @ADR u Relative Addressing Mode l PC is added to the address part of the instruction to obtain the effective address AC M [ PC + ADR ] l Example : LD $ADR u Indexed Addressing Mode l XR (Index register) is added to the address part of the instruction to obtain the effective address l Example : LD ADR(XR) AC M [ ADR + XR ] u Base Register Addressing Mode Not Here l the content of a base register is added to the address part of the instruction to obtain the effective address
Computer System Architecture
Load : transfer from memory to a processor register, usually an AC (memory read) Store : transfer from a processor register into memory (memory write) Move : transfer from one register to another register Exchange : swap information between two registers or a register and a memory word Input/Output : transfer data among processor registers and input/output device Push/Pop : transfer data between processor registers and a memory stack @ : Indirect Address $ : Address relative to PC # : Immediate Mode ( ) : Index Mode, Register Indirect, Autoincrement - register
u Data Manipulation Instruction l 1) Arithmetic, 2) Logical and bit manipulation, 3) Shift Instruction
14 / 22
l l l
16 / 22
Similar to the indexed addressing mode except that the register is now called a base register instead of an index register
index register (XR) : LD ADR(XR)
n
AC M [ ADR + XR ] ADR index register hold an index number that is relative to the address part of the instruction AC M [ BR + ADR ]
BR
u Numerical Example
Addressing Mode Immediate Address Mode Direct Address Mode Indirect Address Mode Register Mode Register Indirect Mode Relative Address Mode Indexed Address Mode Autoincrement Mode u Autodecrement Mode
base register hold a base address the address field of the instruction gives a displacement relative to this base address Address Memory Effective Address 201 500 800 400 702 600 400 399 Content of AC 500 800 300 400 700 325 900 700 450 R1 = 400 600 500 + 202 (PC) 900 325 300 PC = 200 R1 = 400 XR = 100 399 AC 400 500 450 700 800 200 201 202 Load to AC Mode Address = 500 Next instruction
u Status Bit Conditions : Fig. 8-8 l Condition Code Bit or Flag Bit
The bits are set or cleared as a result of an operation performed in the ALU
702 800
u 4-bit status register l Bit C (carry) : set to 1 if the end carry C8 is 1 l Bit S (sign) : set to 1 if F7 is 1 l Bit Z (zero) : set to 1 if the output of the ALU contains all 0 s l Bit V (overflow) : set to 1 if the exclusive-OR of the last two carries (C8 and C7) is equal to 1 l Flag Example : A - B = A + ( 2 Comp. Of B ) : A =11110000, B = 00010100 s
11110000 + 11101100 (2 comp. of B) s 1 11011100
Computer System Architecture
C = 1, S = 1, V = 0, Z = 0
Chap. 8 Central Processing Unit
17 / 22
19 / 22
: Push content of PC onto the stack PC Effective Address : Transfer control to the subroutine
A subroutine call is initiated from the execution of an instruction (CALL) The address of the subroutine call is determined from the address field of an instruction
3) An interrupt procedure stores all the information necessary to define the state of the CPU
n
A subroutine call stores only the program counter (Return address) Chap. 8 Central Processing Unit
Computer System Architecture
18 / 22
20 / 22
When the CPU is executing a program that is part of the operating system
3) Software Interrupts
initiated by executing an instruction (INT or RST) used by the programmer to initiate an interrupt procedure at any desired point in the program
R9
R16 R15
21 / 22
Berkeley RISC I
32 bit CPU, 32 bit instruction format, 31 instruction 3 addressing modes : register, immediate, relative to PC
22 / 22
Instruction Set : Tab. 8-12 Instruction Format : Fig. 8-10 Register Mode : bit 13 = 0
S2 = register Example) ADD R22, R21, R23
n
31 24 23 19 18 14 13 12 54 0 Opcode Rd Rs 0 Not used S2 8 5 5 1 8 5 (a) Register mode : (S2 specifies a register) 31 24 23 19 18 14 13 12 Opcode Rd Rs 1 8 5 5 1 31 24 23 19 18 Opcode COND 8 5 0 S2 13 0 Y 19
PC Relative Mode
Y = 19 bit relative address Example) JMPR COND, Y
n
RISC Architecture Originator Architecture Originator Alpha DEC MIPS MIPS Technologies PA-RISC Hewlett Packard PowerPC Apple, IBM, Motorola Sparc Sun i960 Intel
Licensees Mitsubishi, Samsung NEC, Toshiba Hitachi, Samsung Bul Fujitsu, Hyundai Intel only (Embedded Controller)