Computer Organization and Architecture: Chapter Four
Computer Organization and Architecture: Chapter Four
Computer Organization and Architecture: Chapter Four
Architecture
Chapter Four
12/17/2020 1
Introduction
In this chapter we introduce a basic computer and show how its operations can
be specified with RTL statements.
Every different processor type has its own design (different registers, buses,
micro operations, machine instructions, etc)
We will introduce processor organization and the relationship of the RTL
Instruction Codes
Computer Registers
Computer Instructions
Instruction Cycle
Design of Basic Computer
12/17/2020 2
4.1 Instruction Codes
Program: A set of instructions that specifies operation, operands,
and sequence of processing that has to occur, S/W = Program + Data
The instructions of a program, along with any needed data are
stored in memory.
The CPU reads the next instruction from memory.
It is placed in an Instruction Register(IR)
Control circuitry in control unit then translates the instruction
into the sequence of micro-operations necessary to implement it.
12/17/2020 3
Computer Instruction: A binary code that specifies a sequence of micro-
operations for the computer. Every computer has its own unique instruction code.
Instruction code: is a group of bits instructing the computer to perform a specific
operation. It is divided into parts, each with particular meaning.
I. Operation code(Opcode): the most important part of instruction code
A group of bits that specify the “macro” operation to be performed by the
instruction. Example: add, subtract, multiply, shift, and complement.
that specifies the operation for that instruction.
II. Operand(address): that specifies the registers or locations in memory to
use for that operation
4
The Basic Computer has two components, a processor and memory
The operand part of the instruction has several different formats
depending on the number and type of operands.
12/17/2020 6
3-Operand Instructions
2-Operand Instructions
• Two operand instructions are the most common.
ADD R1, R2
R1 = R1 + R2
12/17/2020 7
1-Operand Instructions
• Single operand instructions are mainly used in
microprocessors where one of the source operands (and
the destination) is implicit.
• These computers use an “accumulator” as part of every
instruction.
ADD B => AC = AC + B
12/17/2020 8
Addressing modes:
• There are several types of operands that can be used with the
different instructions. These translate into the different addressing
modes.
• Immediate address :when the second part of the instruction code
specifies an operand.
12/17/2020 9
12/17/2020 10
12/17/2020 11
Indirect address:
• when the second part specifies an address in a memory where we can find
the true address of the operand.
12/17/2020 12
Effective Address
12/17/2020 13
Computer Registers
A processor has many registers
to hold instructions after it has been fetched from memory,
addresses of operands need to be accessed data manipulated with
accumulator,
general purpose register, and others.
12/17/2020 14
There are four registers that are common to most CPUs:
Program Counter (PC)
- holds the memory address of the next instruction
- Always points to the next instruction.
- It is incremented after each instruction fetch.
- A call instruction causes the new address to be loaded into the PC.
12/17/2020 15
CPU With Systems Bus
12/17/2020 16
Address Register (AR):
- the processor needs to keep track of what locations in memory it is
addressing
- Connects directly to the CPU’s address bus.
- Addresses for memory references are placed in AR before the memory
reference is executed.
12/17/2020 17
Accumulator Register (AC):
it is the general purpose processor register
It holds one of the address of operand
in Single-Address CPU to contain one of the
operand before operation and the result after
operation.
12/17/2020 18
Data transfer instructions
- Moves data from one place to another, without changing the data
contents. The most common transfer are between memory and
processor registers, between processor registers and IO, and between
processor register themselves.
12/17/2020 19
- Store instruction transfers data from register(s),(Accumulator) to
memory.
12/17/2020 20
General Register Organization
- Intermediate data are needed to be stored like pointers, counters, return
address, temp results, and partial products during multiplications.
- Cannot save them in main memory because their access is time
consuming.
- It is more efficient and faster to be stored inside processor.
- So the solution is designing multiple registers inside processor and
connects them through a common bus.
- In Basic Computer, there is only one general purpose register, the
Accumulator (AC) but in modern CPUs, there are many general
purpose registers.
- It is advantageous to have many registers
- Transfer between registers within the processor are relatively fast
12/17/2020 21
Stack Organization
- Stack is a storage device that stores information in a way that
the item is stored last is the first to be retrieved (LIFO).
- Stack in computers is actually a memory unit with address
register (stack pointer SP) that can count only.
- SP value always points at top item in stack.
- The two operations done on stack are
• PUSH (Push Down), operation of insertion of items into
stack
• POP (Pop Up), operation of deletion item from stack
Those operation are simulated by INC and DEC stack register (SP).
12/17/2020 22
The next example shows 64- word register stack or location
stack unit with SP that stores address of the word that is
currently on the top of stack.
12/17/2020 23
Note that 3 items are placed in the stack A, B, and C.
Item C is in top of stack so that SP holds 3 which the address of
item C.
- Then you can continue this until you reach final answer.
Example
Expression A*B + C*D is written in RPN as AB*CD*+. And will
computed as
(A*B) CD *+
(A*B)(C*D)+
12/17/2020 26
Example
Convert infix notation expression (A + B)*(C * (D + E) + F) to
RPN?
AB+ DE+ C * F+ *.
Will be computed as (A+B) (D+E) C * F + *
12/17/2020 27
Implementation of Instruction Format
12/17/2020 28
Zero address instructions
Instruction: ADD
Push and pop operations need to specify one address involved
in data transfer.
Instruction: POP X
Evaluate X = ( A + B ) * ( C + D )
12/17/2020 29
PUSH A TOS A
PUSH B TOS B
ADD TOS ( A B )
PUSH C TOS C
PUSH D TOS D
ADD TOS (C D )
MUL TOS (C D ) ( A B )
POP X X TOS
12/17/2020 30
One address instructions
LOAD A AC M [ A ]
AC AC M [ B ]
ADD B
M [ T ] AC
STORE T
All operations are done between the AC register and memory operand
12/17/2020 31
Two address instructions
Assumes that the destination address is the same as that of
the first operand. Can be a memory address or a register
name.
Instruction: ADD R1, R2
MOV R1, A R1 M [ A]
Micro operation: R1 R1 + R2
MOV R2, B R 2 M [B ]
ADDR1, R2 R1 R1 R 2
M [ x] R1
MOV X, R1
12/17/2020 32
Three address organization
12/17/2020 33
Example: Show how can the following operation be performed using:
c.
b. LOAD A
a. MOV R1, A AC M[A]
ADD R1, A, B R1 M[A] ADD B
R1 M[A] + M[B] ADD R1, B AC AC + M[B]
ADD R2, C, D R1 R1 + M[B] STORE T
R2 M[C] + M[D] MOV R2, C M[T ] AC
MUL X, R1, R2 R2 M[C] LOAD C
ADD R2, D AC M[C]
M[X] R1 * R2 R2 R2 + M[D] ADD D
MOV X, R2 AC AC + M[D]
M[X] R2 MUL T
MUL X, R1 AC AC * M[T ]
M[X] R1 * M[X] STORE X
M[X] AC Store
12/17/2020 34
d. Zero-address instructions
(stack organization)
Push value
Else If operator is encountered: Pop, pop, operation, push
Pop operand pop another operand then perform an operation and push the
result back into the stack.
PUSH A TOS A Push
PUSH B TOS B Pop, pop, operation, push
ADD TOS (A+B)
PUSH C TOS C
PUSH D TOS D Pop, pop, operation, push
ADD TOS (C+D)
MUL TOS (C+D)*(A+B)
POP X M[X] TOS
(*TOS stands for top of stack).
12/17/2020 35
INSTRUCTION CYCLE:
12/17/2020 36
Example: Instruction cycle
• Add operation
ADD A, B
– Fetch the ADD instruction
– Decode the instruction
– Read content of memory location A into the processor
– Read content of memory location B into the processor
– Add the two values
– Write the result from processor to memory location A
12/17/2020 37
Fetching the instruction
12/17/2020 38
Decoding the Instruction
• When cycle T1 is over, the instruction code read from memory is in IR.
– It needs to be decoded to determine what operations are to be done
next.
– Bits 12 – 14 of the instruction contain the instruction code.
– Bit 15 is the Direct/Indirect bit
– Bits 0 – 11 May carry the effective address or the operation
depending on the type of instruction.
– In Micro-operation form, this can be written as:
– T2: D0, …, D7 Decode IR(14-12), AR IR(11-0), I
IR(15)
12/17/2020 39
Input Output & Interrupts
– Computer must communicate with external device to receive and send
data with it.
– Instructions and data must come to computer from external input device.
– The terminal sends and receives 8 bit data converted to serial information
and receives serial information and convert it back to parallel 8 bits.
12/17/2020 40
– The serial info from the keyboard is received serially and
shifted into INPR.
– The serial info for the printer is stored in the OUTR and
converted to serial and sends to the printer.
Interrupt Initiated IO and Interrupt
– For slow device transfer it can be considered wasting a lot
of time (different data transfer rate between IO and
processor).
– The solution will be the device can interrupt and tell
processor when it wants to be served.
12/17/2020 41
Design of Basic Computer
Hardware Components of Basic Computer should contain:
A memory unit:
Registers:
Decoders:
Common bus:
Control logic gates:
Adder and Logic circuit: Connected to AC
12/17/2020 42
D!!
E N
12/17/2020 43