Unit III CPU Organization PG 1-20
Unit III CPU Organization PG 1-20
Unit III CPU Organization PG 1-20
2009,
2011
Ans.- CPU ORGNIZATION- CPU is the major part of computer that performs the bulk of data-
processing operations. CPU is the brain of a computer. Its primary function is to execute
programs. The program, which is to be executed, is stored in the main memory. A program is a
sequence of instructions to perform a specified task. The CPU fetches instruction codes from the
memory and decodes them. The necessary data for the execution of an instruction may be in
register of the CPU or in the memory. When the required data for the execution of an instruction
is at hand, the CPU executes the instruction. When all the instructions of a program are executed,
the CPU gives the result. The result is placed in the memory or sent to an output device
according to the instruction given in the program. Besides executing programs, the CPU also
controls input devices, output devices and other components of the computer. It controls input
and output devices to receive and send data. Under its control programs and data are stored in the
memory and display on the CRT screen. The CPU of a small computer is microprocessor. The
CPU of a large computer contains a number of microprocessors. They work in parallel to execute
a program. This makes computer more powerful and faster.
The CPU is made up of three major parts- the register set, ALU and CU. The ALU performs the
required micro operations for executing the instructions. The function of an arithmetic and logic
unit is to perform arithmetic and logic operations. Usually an ALU performs the following
arithmetic and logic operations.–
Addition, subtraction, multiplication,
division, logical AND, OR, EXCLUSIVE-
OR, Complement, Increment, Decrement,
Left or right shift, clear etc. Other
mathematical operations such as
exponential, logarithmic, trigonometric
and floating-point operations are not performed by ALU. These operations are performed by
special purpose math processor called floating-point unit (FPU). Modern microprocessors
contain an FPU on the microprocessor chip itself (i.e. an On-chip FPU). Some cheaper
microprocessor which is used for simple automatic control applications may not contain on-chip
FPU. Such processors use either software or employ a math processor IC (or math coprocessor)
in the microprocessor-based system. The use of software for such mathematical operations
makes execution slower. Math processors speed up program execution and reduce programming
complexity.
The Control Unit of CPU controls the entire operation of the computer. This very important
section of the CPU really acts as the brain of the computer. It also controls all other devices such
as memory, input and output devices connected to the CPU. It fetches instructions from the
memory, decodes the instruction, interprets the instruction to know what tasks are to be
performed and sends suitable control signals to other components to perform further necessary
steps to execute the instruction. It maintains order and directs the operation of the entire system.
It gives order to ALU what operations are to be performed. It generates timing and control
signals, and provides them for all operations. It controls the data flow between CPU and
peripherals (including memory). It provides status, control and timing signals that the memory
and I/O devices require. The control unit supervises the transfer of information among the
registers and instructs the ALU as to which operation to perform. The CPU performs a variety of
functions dictated by the type of instructions that are incorporated in the computer.
Under the control of the control unit the instructions are fetched from the memory one after
another for execution until all the instructions are executed. In a Von-Neumann type processor
such as Intel 8085, for fetching and executing an instruction the following steps are performed
under its control:
1. The address of the memory location where instruction lies, is placed on the address bus.
2. Instruction is read from the memory.
3. The instruction is sent to the decoding circuitry for decoding.
4. Addresses and data required for the execution of the instruction are read from the
memory.
IN 80h.
5. These data/addresses are sent to the other section for processing.
6. The results are sent to the memory or kept in some register e.g. ADD A, M; STA D050h.
7. Necessary steps are taken to fetch next instruction. For this the content of program
counter register is incremented.
Register- A CPU contains a number of registers to store data temporarily during the execution of
a program. The number of registers differs from processor to processor. The register set stores
intermediate data used during the execution of the instructions. Some processor contains more
registers, some less. Memory locations are needed for storing pointers, counters, return
addresses, temporary results, and partial products during multiplication. Having to refer to
memory locations for such applications is time consuming because memory access is the most
time consuming operation in computer. It is more convenient and more efficient to store these
intermediate values in processor registers. Registers are classified as follows-
General Purpose Registers- These registers store data and intermediate results during the
execution of a program. They are accessible to users through instructions if the users are working
in assembly language. MOV B, C; ADD B (AC (AC) + (B)). In 8085, B, C, D, E, H and L are
general purpose or scratch pad registers.
Accumulator- It is the most important general-purpose register having multiple functions. It is
most efficient in data movement (IN 80H) (AC port (80H)), OUT 80H (port (80H) (AC));
arithmetic (ADD B), and logical operations (AND B). Its functions depend on the design of the
processor whether the processor is an accumulator-based processor or general purpose register-
based processor (ADD R1, R2, R3) (R1 R2 + R3)). It has some special features that the other
general-purpose registers do not have. In an accumulator-based processor design, the
accumulator holds one of the operands of arithmetic and logical operation. After the execution of
arithmetic and logical instructions, the result is placed in the accumulator. All data transfer
between the CPU and device/port are performed through the accumulator.
Special Purpose Registers- A CPU contains a number of special purpose registers for different
purposes. These are Program Counter (PC), Stack Pointer (SP), Instruction Register (IR), Flag
/Status Register, Data Register (DR)/ Memory Buffer Register (MBR), Memory Address
Register (MAR) etc.
Program Counter (PC)- The Program Counter keeps track of the address of the instruction
which is to be executed next. So, Program counter holds the memory location of the next
executable instruction. It is auto incremented. In case of jump instruction its contents are
modified, and program jumps to the memory location which contains the desired instruction
to be executed next. The processor which employs Von Neumann architecture contains a
program counter.
Stack Pointer (SP)- The stack is a sequence of memory location defined by the user. It is used
to save the contents of a register if it is required during the execution of a program. Stack
pointer holds the top-empty location of stack. Thus it indicates upto what memory locations
the stack is already filled up. It may be incremented or decremented manually or
automatically by PUSH/POP or CALL/RETURN instruction respectively.
Flag register (Program Status Word-PSW)- It is bit oriented register, used to indicate the
status of obtained result and control. In 8085 microprocessor, the flags register can have a
total of eight flags. Thus a flag can be represented by 1 bit of information. But only five flags
are implemented in 8085. And they are:
Carry flag (Cy),
Auxiliary carry flag (AC),
Sign flag (S),
Parity flag (P), and
Zero flag (Z).
The respective position of these flag bits in flag register has been show the below figure. The
positions marked by “x” are to be considered as don't care bits in the flags register. The user is
not required to memorize the positions of these flags in the flags register.
AC- Accumulator register is special type of register which hold the one operand prior
performing arithmetic, logical, shift or I/O operation in accumulator based CPU.
PC- Program counter holds the memory location of the next executable instruction. It is
auto incremented.
Scatch Pad- It is also called general purpose registers (GPR). It is used to store
intermediate values.
SP- Stack pointer holds the top-empty location of stack. It may be incremented or
decremented manually or automatically by PUSH/POP or CALL/RETURN instruction
respectively.
AR- Address register holds the location of currently executable instruction.
Flag register- It is bit oriented register, used to indicate the status of obtained result and
control.
DR- Date register hold the operand and code of the instruction during the execution of
instruction
8085 (Microprocessor)
1. It is an 8-bit microprocessor. It can accept or provide 8 bit data simultaneously.
2. It has 8 bit ALU that can perform 8 bit operations.
3. It is based on NMOS technology.
4. It provides 16 address lines, hence it can
access 216 = 64 KB of memory.
5. It generates 8 bit I/O address; hence it can
access 28 = 256 I/O ports.
6. It has 8-bit internal data bus and registers.
7. It provides 5 level interrupts.
8. It provides two serial I/O lines.
9. 8085 was the first processor that required
only single +5V power Supply.
10. It has an on-chip clock generator.
Serial I/O Controller
S1 S0 Operation
0 0 Halt
0 1 Write
1 0 Read
1 1 Fetch
̅̅̅̅̅(Output)- It is a control signal sent by the microprocessor to control read operation. The
selected memory or I/O device is read when ̅̅̅̅̅ is low.
̅̅̅̅̅ (Output)- It is a control signal sent by the microprocessor to control write operation. The
data on the data bus are written into the selected memory or I/O device when is ̅̅̅̅̅ low.
HOLD (Input)- When an external device wants to use the address and data bus for data transfer,
it sends HOLD signal to the microprocessor. Having received the HOLD signal, the
microprocessor completes its current machine cycle at hand, and then gives up the control of
buses to allow the external device to use them.
HLDA (Output)-It is a HOLD acknowledgement signal. It is sent by the microprocessor to the
external device to indicate that the HOLD request has been received. On the completion of data
transfer, the external device removes the HOLD request. The HLDA goes low after the removal
of HOLD request. The CPU takes over the control of the buses half cycle after the HLDA goes
low.
INTR (Input)- It is an interrupt signal of the lowest priority.
̅̅̅̅̅̅̅ (Output)- it is an interrupt acknowledgement signal. It is issued by microprocessor after
INTR is received.
RST 7.5, RST 6.5, RST 5.5 and TRAP (Input)- These are interrupts. The TRAP is a non-
maskable interrupt and has the highest priority. Others are maskable interrupt.
RESET IN (Input)- When this signal is applied the CPU is brought to reset condition. The
content of the program counter becomes zero.
RESET OUT (Output)- The signal indicates that the CPU is being reset.
READY (Input)- It is an input signal to the microprocessor. It is sent by a peripheral device to
indicate whether it is ready to transfer data or not. If this signal is high it shows that peripherals
are ready to transfer data.
X1 and X2 (Input)- An external crystal oscillator is connected to these terminals to supply clock
for the microprocessor. The crystal oscillator derives an internal circuitry which is within the
microprocessor to produce suitable clock for the operation of the microprocessor.
CLK OUT (Output)- The clock is also required by some other ICs of the computer. Hence CLK
is a clock output from the microprocessor, which can be utilized for the operation of other ICs.
SID (Input)- It is an input line for serial data. The data received from this are loaded into the 7th
bit of the accumulator when RIM instruction is executed.
SOD (Output)- It is an output lines for serial dat. The 7th bit of the accumulator is sent through
this line when SIM instruction is executed.
Instruction format
A computer will usually have a variety of instruction code formats. It is the function of control
unit within the CPU to interpret each instruction code and provide the necessary control
functions needed to process the instruction. The format of instruction is usually depicted in a
rectangular box symbolizing the bits of the instruction as they appear in memory words or in a
control register. The bits of the instructions are divided into groups called fields. The common
fields found in instruction formats are:
1. An operation code field that specifies the operation to be performed.
2. An address field that designates a memory address or a processor register.
3. A mode field that specifies the way the operand or the effective address is determined.
The operation code field of an instruction is a group of bits that define various processor
operations, such as add, subtract, complement, and shift. The bits that define the mode field of an
instruction code specify a variety of alternatives for choosing the operands from the given
address.
An instruction is a command given to the computer to perform a specified operation on given
data. Each instruction consists of two parts: an opcode (operation code) and an operand. The first
part of an instruction, which specifies the operation to be performed, is known as opcode. The
second part of an instruction called operand is the data on which computer performs the specified
operation.
Operations specified by computer instructions are executed on some data stored in memory or
processor registers. Operand residing in memory are specified by memory address. Operands
residing in processor registers are specified with a register address. A register address is a binary
number of k bits that defines one of 2k registers in the CPU. Thus a CPU with 16 processor
registers R0 through R15 will have a register address field of four bits. The binary number 0101,
for example, will designate register R5.
Computers may have instructions of several 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. Most computers fall into one of three types of CPU
organization:
1. Single accumulator organization
2. General register organization
3. Stack organization
In an accumulator based organization, one special register is treated as an accumulator which
store one operand value prior performing arithmetic, logical, shift or other operation namely
Input and output operations. All operations are performed with an implied accumulator register.
The instruction format in this type of computer uses one address field. For example, the
instruction that specifies an arithmetic addition is defined by an assembly language instruction as
ADD X
Where X is the address of the operand. The ADD instruction in this case results in the operation
AC (AC) + M[X]. AC is the accumulator register and M[X] symbolizes the memory word
located at address X.
The instruction format of a general purpose register type of organization needs three register
address fields. Thus the instruction for an arithmetic addition may be written in an assembly
language as
ADD R1, R2, R3
to denote the operation R1 (R2) + (R3). The number of address fields in the instruction can be
reduced from three to two if the destination register is the same as one of the source register.
Thus the instruction
ADD R1, R2
would denote the operation R1 (R1) + (R2). Only register addresses for R1 and R2 need be
specified in this instruction.
General purpose register type computers employ two or three address fields in their instruction
format.
In a stack oriented computer, there is no address part in an instruction. This is because the
operation is performed on the two items that are on top of stack. The instruction
ADD
in a stack computer consists of an operation code only with no address field. This operation has
the effect of popping the two top numbers from the stack, adding the numbers and pushing the
sum into the stack. There is no need to specify operands with an address field since all operands
are implied to be in the stack
Mnemonic- CMA
Opcode- CMA
Operand- NA
Hex Code- 2FH
Binary code- 0010 1111
Note – The length of these instructions is 8-bit; each requires one memory location. The mnemonic
is always followed by a letter (or two letters) representing the registers (such as A, B, C, D, E, H, L
and SP).
2. Two-byte instructions –
Two-byte instruction is the type of instruction in which the first 8 bits indicates the opcode and the
next 8 bits indicates the operand.
Example-1:
Task- Load the hexadecimal data 32H in the accumulator.
Mnemonic- MVI A, 32H
Opcode- MVI
Operand- A, 32H
Hex Code- 3E
32
Binary code- 0011 1110
0011 0010
Example-2:
Task- Load the hexadecimal data F2H in the register B.
Mnemonic- MVI B, F2H
Opcode- MVI
Operand- B, F2H
Hex Code- 06
F2
Binary code- 0000 0110
1111 0010
Example-3:
Task- Load input content from specified port
Mnemonics – IN 80H
Opcode- IN
Operand- 80H (address)
Hex code- DB
80H
Binary code- 11011011 10000000
Note – This type of instructions need two bytes to store the binary codes. The mnemonic is always
followed by 8-bit (byte) data.
3. Three-byte instructions –
Three-byte instruction is the type of instruction in which the first 8 bits indicates the opcode and
the next two bytes specify the 16-bit address. The low-order address is represented in second byte
and the high-order address is represented in the third byte.
Example-1:
Task- Load contents of memory 2050H in the accumulator.
Mnemonic- LDA 2050H
Opcode- LDA
Operand- 2050H
Hex Code- 3A
50
20
Binary code- 0011 1010
0101 0000
0010 0000
Example-2:
Task- Transfer the program sequence to the memory location 2050H.
Mnemonic- JMP 2085H
Opcode- JMP
Operand- 2085H
Hex Code- C3
85
20
Binary code- 1100 0011
1000 0101
0010 0000
Note – These instructions would require three memory locations to store the binary codes. The
mnemonic is always followed by 16-bit (or adr).
Addressing Modes– The operation field of an instruction specifies the operation to be
performed. This operation must be executed on some data stored in computer registers or
memory words. The way the operand are chosen during program execution is dependent on the
addressing mode of the instruction. The addressing mode specifies a rule for interpreting or
modifying the address field of the instruction before the operand is actually referenced. The term
addressing modes refers to the way in which the operand of an instruction is specified. The
addressing mode specifies a rule for interpreting or modifying the address field of the instruction
before the operand is actually executed. The way of specifying data to be operated by an
instruction is called addressing mode. Computers use addressing mode techniques for the
purpose of accommodating one or both the following provisions:
1. To give programming versatility to the user by providing such facilities as pointers to
memory, counters for loop control, indexing of data, and program relocation.
2. To reduce the number of bits in the addressing field of the instruction.
Types of addressing modes –
In 8085 microprocessor there are 5 types of addressing modes:
1. Immediate Addressing Mode –
In immediate addressing mode the source operand is always data. If the data is 8-bit, then
the instruction will be of 2 bytes, if the data is of 16-bit then the instruction will be of 3
bytes. In this mode, the operand is specified in the instruction itself. In other words, an
immediate-mode instruction has an operand field rather than address field. The operand
field contains the actual operand to be used in conjunction with the operation specified in
the instruction. Immediate-mode instructions are useful for initializing registers to a
constant value.
Examples:
MVI B 45 (move the data 45H immediately to register B)
LXI H 3050 (load the H-L pair with the operand 3050H immediately)
JMP address (jump to the operand address immediately)
Effective Address = Address of Instruction