Central Processing Unit
Central Processing Unit
INTRODUCTION
GENERAL REGISTER ORGANIZATION
• memory locations are needed for storing pointers,
counters, return addresses, temporary results, and partial
products.
• Having to refer to memory locations for such applications is
time consuming because memory access is the most
time-consuming operation.
• It is more Control Register set Arithmetic Logic unit (ALU)
Major components of CPU.
• convenient and more efficient to store these intermediate
values in processor registers.
• When a large number of registers are included in the CPU, it
is most efficient to connect them through a common bus
system
• A bus organization for seven CPU registers is shown in Fig.
• The output of each register is connected to two
multiplexers (MUX) to form the two buses A and B.
• The selection lines in each multiplexer select one register or
the input data for the particular bus.
• The A and B buses form the inputs to a common arithmetic
logic unit (ALU).
• The operation selected in the ALU determines the
arithmetic or logic micro-operation that is to be performed.
• The result of the micro-operation is available for output
data and also goes into the inputs of all the registers.
• The register that receives the information from the output
bus is selected by a decoder.
• The decoder activates one of the register load inputs, thus
providing a transfer path between the data in the output
bus and the inputs of the selected destination register.
• For example, to perform the operation.
• R1 ← R2 + R3
• the control must provide binary selection
variables to the following selector inputs:
• 1. MUX A selector (SELA): to place the content of
R2 into bus A.
• 2. MUX B selector (SELB): to place the content of
R3 into bus B.
• 3. ALU operation selector (OPR): to provide the
arithmetic addition A + B.
• 4. Decoder destination selector (SELD): to
transfer the content of the output bus into R1.
CONTROL WORD
There are 14 binary selection inputs in the unit, and their combined value
specifies a control word.
It consists of four fields.
Three fields contain three bits each, and one field has five
bits.
The three bits of SELA select a source register for the A
input of the ALU.
The three bits of SELB select a register for the B input of
the ALU.
The three bits of SELD select a destination register using
the decoder and its seven load output.
The five bits of OPR select one of the operations in the ALU
EXAMPLE OF MICRO OPERATIONS
• R1 ← R2 − R3
• Field : SELA SELB SELD OPR
• Symbol : R2 R3 R1 SUB
• Control word: 010 011 001 00101
STACK ORGANIZATION
• A useful feature that is included in the CPU of
most computers is a stack or last-in, first-out
(LIFO) list.
• A stack is a storage device that stores information
in such a manner that the item stored last is the
first item retrieved.
• The operation of a stack can be compared to a
stack of trays.
• The last tray placed on top of the stack is the first
to be taken off.
• The stack in digital computers is essentially a
memory unit with an address register
• The register that holds the address for the stack is
called a stack pointer (SP) because its value
always points at the top item in the stack
• The two operations of a stack are the insertion
and deletion of items.
• The operation of insertion is called push (or
push-down).
• The operation of deletion is called pop (or
pop-up).
• These operation are simulated by incrementing or
decrementing the stack pointer register.
REGISTER STACK
REGISTER STACK
• A stack can be placed in portion of a large memory or it can
be organized as a collection of a finite number of memory
words or registers.
• Figure shows the organization of a 64-word register stack.
• The stack pointer register SP contains a binary number
whose value is equal to the address of the word that is
currently on top of the stack.
• Three items are placed in the stack: A, B, and C, in that
order.
• Item C is on top of the stack so that the content of SP is now
3.
• To remove the top item, the stack is popped by reading the
memory word at address 3 and decrementing the content
of SP
• Item B is now on top the stack since SP holds address 2.
• To insert a new item, the stack is pushed by incrementing SP and
writing a word in the next-higher location in the stack
• In a 64-word stack, the stack pointer contains 6 bits because 26 =
64.
• Since SP has only six bits, it cannot exceed a number greater than
63 (111111 in binary).
• When 63 is incremented by 1, the result is 0 since 111111 + 1 =
1000000 in binary, but SP can accommodate only the six least
significant bits.
• Similarly, when 000000 is decremented by 1, the result is 111111.
• The one bits register FULL is set to 1 when the stack is full, and the
one-bit register EMTY is set to 1 when the stack is empty of items.
• DR is the data register that holds the binary data to be written into
or read out of the stack. .
• push operation: Initially, SP is cleared to 0,
EMTY is set to 1, and FULL is cleared to 0, so
that SP points to the word at address 0 and
the stack is marked empty and not full.
• If the stack is not full (if FULL = 0), a new item
is inserted with a push operation.
• The push operation is implemented with the
following sequence of microoperations:
• The stack pointer is incremented so that it
points to the address of the next-higher word.
• A memory write operation inserts the word
form DR into the top of the stack.
• Note that SP holds the address of the top of
the stack and that M[SP] denotes the memory
word specified by the address presently
available in SP.
• The pop operation: A new item is deleted
from the stack if the stack is not empty (if
EMTY = 0). The pop operation consists of the
following sequence of microoperations:
The top item is read from the stack into DR. the stack
pointer is then decremented. If its value reaches zero, the
stack is empty, so EMTY is set to 1
• A stack can exist as a stand-alone unit or can be
implemented in a random-access memory
• portion of computer memory partitioned into
three segments: program, data, and stack.
• The program counter PC points at the address of
the next instruction in the program.
• The address register AR points at an array of data.
• The stack pointer SP points at the top of the stack
• PC is used during the fetch phase to read an
instruction. AR is used during the execute phase
to read an operand. SP is used to push or pop
items into or & from the stack.
• We assume that the items in the stack
communicate with a data register DR . A new
item is inserted with the push operation as
follows:
SP <- SP - 1
M[SP] <- DR
• A new item is deleted with a pop operation as
follows:
• DR <-M[SP]
• SP <- SP + 1
Reverse Polish Notation
• A stack organization is very effective for
evaluating arithmetic expressions
• The common arithmetic expressions are written in
infix notation
• Eg A*B + C *D
• The Polish mathematician Lukasiewicz showed
that arithmetic expressions can be represented in
– prefix notation -(Polish notation), places the operator
before the operands.
– The postfix notation, ( reverse Polish notation (RPN)),
places the operator after the operands.
• The following examples demonstrate the
three representations
– A+ B Infix notation
– + AB Prefix or Polish notation
– AB + Postfix or reverse Polish notation
The reverse Polish notation is in a form suitable for
stack manipulation.
The expression A*B + C *D is written in reverse
Polish notation as AB * CD* +
Evaluation of Arithmetic Expressions
• The following numerical example may clarify
this procedure.
• Consider the arithmetic expression
• (3 * 4) + (5 * 6)
• In reverse Polish notation, it is expressed as
34*56*+
Data Transfer and Manipulation
• Most computer instructions can be classified
into three categories:
– Data transfer instructions-transfer of data from
one location to another
– Data manipulation instructions -perform
arithmetic, logic, and shift operations.
– Program control instructions -provide
decision-making capabilities and change the path
of the program when executed in the computer.
Data Transfer Instructions
• The most common transfers are between
– memory and processor registers
– between processor registers and input or output
– between the processor registers themselves.