Cos141 C CPU-InstFormat-Modes
Cos141 C CPU-InstFormat-Modes
Computer Components
The Control Unit (CU), Arithmetic and Logic Unit (ALU) constitute the Central Processing Unit (CPU)
Input/output (I/O module) enable Data and instructions to get into the system and results to get
out
The main memory (RAM), enable temporary storage of code and results.
Bus Interconnection
A bus is a communication pathway connecting two or more devices
• It is often grouped
A number of channels in one bus
e.g. 32 bit data bus is 32 separate single bit channels
There are a number of possible interconnection systems
• Single and multiple bus structures are most common
• Control/Address/Data bus (PC)
• Unibus (DEC-PDP)
• Lots of devices on one bus leads to:
o Propagation delays
o Long data paths mean that coordination can adversely affect performance If aggregate
data transfer approaches bus capacity
• Most systems use multiple buses to overcome these problems
Computer Function
The basic function performed by a computer is execution of a program (a set of instructions stored in memory).
• The two steps of Instructions Cycle are:
Fetch
Execute
Fetch Cycle:
Program Counter (PC) holds address of next instruction to fetch,
Processor fetches instruction from memory location pointed to by PC,
PC is increment; Unless told otherwise,
The Instruction is loaded into Instruction Register (IR)
Execute Cycle:
The Processor interprets instruction and performs required actions, such as:
data transfer between CPU and main memory
Data transfer between CPU and I/O module
Arithmetic and logical operations on data
Alteration of sequence of operations; e.g. jump (branch)
There are two parts in instruction: - opcode (operation code e.g. MOV, ADD, JMP,) and operand
(data/memory location to operate on e.g. 7, r0, x).
In fetch cycle the opcode of instruction is brought into CPU.
The operand, at first, is sent to Data Register (DR), then to Instruction Register (IR).
Decoder accesses the opcode, decodes it and type of operation is declared to CPU for execution
cycle is started.
Opcode: - indicates the operation to be performed, e.g., 92 above indicates a copy operation. So we
need two operands; source and destination
Operand - represents:
o nature of operands (data or address) above; operand 1 is address and operand 2 is data
o mode(register or memory), operand 1 is memory, and operand 2 is immediate data
Types of Instruction
Computers may have instructions of different lengths, containing varying number of addresses.
The number of address fields in the instruction format of a computer depends on the internal
organization of its registers.
Let us illustrate the influence of the number of addresses on computer programs, we will evaluate the
arithmetic statement X=(A+B) *(C+D) using Zero, one, two, or three address instructions.
1. Three-Address Instructions:
ADD R1, A, B; R1 M[A] + M[B]
ADD R2, C, D; R2 M[C] + M[D]
MUL X, R1, R2; M[X] R1 * R2
It is assumed that the computer has two processor registers R1 and R2. The symbol M[A] denotes the operand at
memory address location A.
2. Two-Address Instructions:
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
3. One-Address Instruction:
LOAD A; Ac M[A]
ADD B; Ac Ac + M[B]
STORE T; M[T] Ac
LOAD C; Ac M[C]
ADD D; Ac Ac + M[D]
MUL T; Ac Ac * M[T]
STORE X; M[X] Ac
Here, T is the temporary memory location required for storing the intermediate result.
4. Zero-Address Instructions:
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 ; M[X] TOS
•2-address instructions
Operation Source, Destination
e.g. Move B, C; C=B
Add A, C; C=C+A
Here Source2 is implicitly the destination
•1-address instructions
e.g. Load A
Store C
•0-address instructions
e.g. Stop
Addressing Modes
The Mode are techniques that define how the CPU locates data or instruction in memory during instruction
execution. It stipulates the rule for interpreting or modifying the address field of the instruction before the
operand is actually referenced.
Computers use addressing mode techniques for the following purpose:
To give programming versatility to the user by providing such facilities as pointers to memory, counters
for loop control, indexing of data and various other purposes.
To reduce the number of bits in the addressing field of the instructions.
Some computers use a single binary for operation & Address mode.
The mode field is used to locate the operand.
Address field may designate a memory address or a processor register.
There are 2 modes that need no address field at all (Implied & immediate modes).
Note: It was mentioned previously that the address field of an instruction may specify either a memory
word or a processor register. When the address field specifies a processor register, the instruction is
said to be in register-mode.
Advantage: no memory reference. Disadvantage: limited operand
This program is coded into machine instruction and is loaded into memory starting at location $0000 0000