Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

2,770 views

Published on

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

Published in:
Education

No Downloads

Total views

2,770

On SlideShare

0

From Embeds

0

Number of Embeds

3

Shares

0

Downloads

86

Comments

0

Likes

3

No embeds

No notes for slide

- 1. Central Processing Unit (CPU) <ul><li>It is the part of the computer that performs bulk of data-processing operation. </li></ul><ul><li>It is made up of 3 major parts as shown below : </li></ul>KAPIL P.C.T.E. Control Register Arithmetic Logic Unit (ALU)
- 2. Components of the CPU <ul><li>The Register set stores intermediate date used during the execution of the instructions. </li></ul><ul><li>The Arithmetic Logic Unit (ALU) performs the required micro-operations for executing the instructions. </li></ul><ul><li>The Control Unit supervises the transfer of information among the registers and instructs the ALU as to which operation to perform. </li></ul>KAPIL P.C.T.E.
- 3. Stack Organization <ul><li>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). </li></ul><ul><li>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. </li></ul><ul><li>The two operations of a stack are the insertion (PUSH) and deletion (POP) of elements. </li></ul><ul><li>PUSH-operation increments the SP. </li></ul><ul><li>POP-operation decrements the SP. </li></ul>KAPIL P.C.T.E.
- 4. Stack Organization (contd) <ul><li>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. </li></ul><ul><li>Fig here shows an organization of 64-word register stack. </li></ul>KAPIL P.C.T.E.
- 5. Operations on Stack <ul><li>PUSH (performed if stack is not full i.e. if FULL = 0): </li></ul>KAPIL P.C.T.E.
- 6. Operations on Stack <ul><li>POP (performed if stack is not empty i.e. if EMTY = 0): </li></ul>KAPIL P.C.T.E.
- 7. Stack implemented in the Computer Memory <ul><li>Stack can also be implemented with RAM attached to a CPU: </li></ul><ul><ul><li>a portion of memory is assigned to a stack operation </li></ul></ul><ul><ul><li>a special register is used as a stack pointer (SP). </li></ul></ul><ul><li>Fig. next shows how a portion of memory partitioned into three segments : Program, Data and Stack. </li></ul>KAPIL P.C.T.E.
- 8. KAPIL P.C.T.E.
- 9. Utility of using Stack(Evaluating Arithmetic Expressions) <ul><li>A stack is effective for evaluating A rithmetic expressions . </li></ul><ul><li>Arithmetic operations are usually written in I nfix Notation : each operator resides between the operands , </li></ul><ul><li>(A * B) + (C * D) </li></ul><ul><li>where * denotes multiplication: </li></ul><ul><ul><ul><li>A * B and C * D has to be computed and stored. </li></ul></ul></ul><ul><ul><ul><li>after the two products, sum (A * B) + (C * D) is computed </li></ul></ul></ul><ul><li>there is no straight forward way to determine the next operation that is performed. </li></ul>KAPIL P.C.T.E.
- 10. Continued <ul><li>Arithmetic expressions can be represented in Prefix Notation (also referred to as Polish Notation) : operators are placed before the operands . </li></ul><ul><li>The Postfix Notation (Reverse Polish Notation (RPN) ) places the operator after the operand. </li></ul><ul><li>E. g .: </li></ul><ul><li>A + B --- Infix notation </li></ul><ul><li>+AB ---- Prefix notation (PN) </li></ul><ul><li>AB+ ---- Postfix notation (RPN) </li></ul>KAPIL P.C.T.E.
- 11. Continued <ul><li>E. g. the expression </li></ul><ul><li>A * B + C * D </li></ul><ul><li>is written in RPN as </li></ul><ul><li>AB* CD*+ </li></ul><ul><li>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. </li></ul>KAPIL P.C.T.E.
- 12. <ul><li>1. * is found </li></ul><ul><li>2. Take the two operands from left: A and B </li></ul><ul><li>3. Compute P = A * B </li></ul><ul><li>4. Replace operands and operator with the result => PCD*+ </li></ul><ul><li>5. continue scan </li></ul><ul><li>6. * is found </li></ul><ul><li>7. Take the two operands from left: C and D </li></ul><ul><li>8. Compute Q = C * D </li></ul><ul><li>9. Replace operands and operator with the result => PQ+ </li></ul><ul><li>10. continue scan </li></ul><ul><li>11. + is found </li></ul><ul><li>12. Take the two operands from left: P and Q </li></ul><ul><li>13. Compute R = P + Q </li></ul><ul><li>14. Replace operands and operator with the result: R </li></ul><ul><li>15. continue scan: no more operators => stop; R is the result of evaluation. </li></ul>KAPIL P.C.T.E.
- 13. Conversion of Expressions from Infix to RPN <ul><li>The conversion from infix to RPN must take into consideration the operational hierarchy of infix notation: </li></ul><ul><ul><ul><li>1. First perform Arithmetic operation inside inner parentheses. </li></ul></ul></ul><ul><ul><ul><li>2. Then perform Arithmetic operation inside outer parentheses. </li></ul></ul></ul><ul><ul><ul><li>3. P erform multiplication and division before addition and subtraction. </li></ul></ul></ul>KAPIL P.C.T.E.
- 14. <ul><li>Example---(A + B)*[ C*( D + E) + F] becomes </li></ul><ul><li>AB+ DE+ C* F+* which is computed: </li></ul><ul><li>1. P = A+ B => PDE+ C* F+* </li></ul><ul><li>2. Q = D+ E => PQC* F+* </li></ul><ul><li>3. R = Q * C => PRF+* </li></ul><ul><li>4. S = R+ F => PS* </li></ul><ul><li>5. T = P* S </li></ul><ul><ul><li>T represents the result: T = AB+ DE+ C* F+* </li></ul></ul>
- 15. Continued <ul><li>RPN is the most efficient method known for evaluating arithmetic expressions. </li></ul><ul><li>Used in electronic calculators. </li></ul><ul><li>Stack is useful for evaluating arithmetic expressions in RPN </li></ul><ul><ul><li>operands are pushed into the stack in the order of appearance (in RPN) </li></ul></ul><ul><ul><li>the topmost operands are popped from the stack and used for the operation </li></ul></ul><ul><ul><li>The result is pushed to replace the popped operands </li></ul></ul><ul><li>Most compilers convert all arithmetic expressions into Polish notation: efficient translation of arithmetic expressions into machine language instructions. </li></ul>KAPIL P.C.T.E.
- 16. Example <ul><li>(3* 4)+( 5* 6) => 34* 56*+ </li></ul>KAPIL P.C.T.E.

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment