16
Central Processing Unit (CPU) It is the part of the computer that performs bulk of data-processing operation. It is made up of 3 major parts as shown below : KAPIL P.C.T.E. 1 Control Register Arithmetic Logic Unit (ALU)

STACK

  • Upload
    pcte

  • View
    2.528

  • Download
    3

Embed Size (px)

DESCRIPTION

These are Power point slides of Stack operations of Basic Computer System Architecture.

Citation preview

Page 1: STACK

Central Processing Unit (CPU)It is the part of the computer that performs

bulk of data-processing operation.It is made up of 3 major parts as shown

below :

KAPIL P.C.T.E. 1

Control

Register

Arithmetic Logic Unit

(ALU)

Page 2: STACK

Components of the CPUThe Register set stores intermediate date

used during the execution of the instructions.

The Arithmetic Logic Unit (ALU) performs the required micro-operations for executing the instructions.

The Control Unit supervises the transfer of information among the registers and instructs the ALU as to which operation to perform.

KAPIL P.C.T.E. 2

Page 3: STACK

Stack Organization A stack is a storage device for storing

information in such a manner that the element stored last is the first to be retrieved (LIFO –Last-in, First-out).

The stack is a memory unit with an address register called a stack pointer (SP), which always points at the top element in the stack.

The two operations of a stack are the insertion (PUSH) and deletion (POP) of elements.

PUSH-operation increments the SP.POP-operation decrements the SP.

KAPIL P.C.T.E.3

Page 4: STACK

Stack Organization (contd)

Stack can reside in a portion of a large memory unit or it can be organized as a collection of a finite number of (fast) registers.

Fig here shows an organization of 64-word register stack.

KAPIL P.C.T.E. 4

Page 5: STACK

Operations on StackPUSH (performed if stack is not full

i.e. if FULL = 0):

KAPIL P.C.T.E. 5

Page 6: STACK

Operations on StackPOP (performed if stack is not

empty i.e. if EMTY = 0):

KAPIL P.C.T.E. 6

Page 7: STACK

Stack implemented in the Computer Memory

Stack can also be implemented with RAM attached to a CPU: a portion of memory is assigned to a stack

operation a special register is used as a stack pointer

(SP).

Fig. next shows how a portion of memory partitioned into three segments: Program, Data and Stack.

KAPIL P.C.T.E. 7

Page 8: STACK

KAPIL P.C.T.E. 8

Page 9: STACK

Utility of using Stack(Evaluating Arithmetic Expressions)A stack is effective for evaluating Arithmetic expressions.Arithmetic operations are usually written in Infix Notation: each

operator resides between the operands,

(A * B) + (C * D)

where * denotes multiplication: A * B and C * D has to be computed and stored. after the two products, sum (A * B) + (C * D) is computed

there is no straight forward way to determine the next operation that is performed.

KAPIL P.C.T.E. 9

Page 10: STACK

ContinuedArithmetic expressions can be represented in Prefix

Notation (also referred to as Polish Notation): operators are placed before the operands.

The Postfix Notation (Reverse Polish Notation (RPN) ) places the operator after the operand.

E. g .:A + B --- Infix notation+AB ---- Prefix notation (PN)AB+ ---- Postfix notation (RPN)

KAPIL P.C.T.E. 10

Page 11: STACK

ContinuedE. g. the expression

A * B + C * Dis written in RPN as

AB* CD*+and is evaluated by scanning from left to right: when operator is found, the operation is performed by using operands on the left side of the operator. The operator and operands are replaced by the result of operation. The scan is continued and the procedure is repeated for every operator.

KAPIL P.C.T.E. 11

Page 12: STACK

1. * is found2. Take the two operands from left: A and B3. Compute P = A * B4. Replace operands and operator with the result => PCD*+5. continue scan6. * is found7. Take the two operands from left: C and D8. Compute Q = C * D9. Replace operands and operator with the result => PQ+10. continue scan11. + is found12. Take the two operands from left: P and Q13. Compute R = P + Q14. Replace operands and operator with the result: R15. continue scan: no more operators => stop; R is the result of

evaluation.

KAPIL P.C.T.E. 12

Page 13: STACK

Conversion of Expressions from Infix to RPN

The conversion from infix to RPN must take into consideration the operational hierarchy of infix notation:

1. First perform Arithmetic operation inside inner parentheses.

2. Then perform Arithmetic operation inside outer parentheses.

3. Perform multiplication and division before addition and subtraction.

KAPIL P.C.T.E. 13

Page 14: STACK

Example---(A + B)*[ C*( D + E) + F] becomesAB+ DE+ C* F+* which is computed:

1. P = A+ B => PDE+ C* F+*2. Q = D+ E => PQC* F+*3. R = Q * C => PRF+*4. S = R+ F => PS*5. T = P* S

T represents the result: T = AB+ DE+ C* F+*

Page 15: STACK

ContinuedRPN is the most efficient method known for evaluating

arithmetic expressions.Used in electronic calculators.Stack is useful for evaluating arithmetic expressions in

RPNoperands are pushed into the stack in the order of

appearance (in RPN)the topmost operands are popped from the stack and

used for the operationThe result is pushed to replace the popped operands

Most compilers convert all arithmetic expressions into Polish notation: efficient translation of arithmetic expressions into machine language instructions.

KAPIL P.C.T.E. 15

Page 16: STACK

Example(3* 4)+( 5* 6) => 34* 56*+

KAPIL P.C.T.E. 16