Stack machine in Computer Organisation
Instruction formats are classified into different types depending upon the CPU organization. CPU organization is again classified into three types based on internal storage: Stack machine, Accumulator machine, General purpose organization or General register. In this article, we will learn about the stack machine in computer organizations.
Stack Machine:
In the stack machine, data is available at the top of the stack by default. The stack acts as a source and destination, push and pop instructions are used to access instructions and data from the stack. There is no need to pass the source and destination address because the default address is top of the stack. In the stack machine, there is no need to pass explicit addresses in the instruction. Therefore the instruction format consists only of the OPCODE (Operation Code) field. This instruction format is known as Zero address instruction.
The two operations of the stack are insertion (push) and deletion (pop) of items in the Stack. However, nothing is pushed or popped in a computer stack.

Example:
Perform the following set of instructions intended for execution on a stack machine:
PUSH B, PUSH X, ADD, POP C, PUSH C, PUSH Y, SUB, POP Z
First PUSH B and X in a stack, then to add first POP X then B, ADD (B+X), POP C=B+X (no data with name C, so the data present is stored in variable C) then POP C.
Similarly, to perform SUB (Y-C) first perform POP operation POP as Z. See in figure below for better understanding:

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
Recommended Posts:
- Clusters In Computer Organisation
- Memory Organisation in Computer Architecture
- Multilevel Cache Organisation
- Difference between Mealy machine and Moore machine
- Infix to Postfix using different Precedence Values for In-Stack and Out-Stack
- Stack Permutations (Check if an array is stack permutation of other)
- Find maximum in stack in O(1) without using additional stack
- Sort a stack using a temporary stack
- Stack | Set 3 (Reverse a string using stack)
- Differences between Computer Architecture and Computer Organization
- Computer Organization | Basic Computer Instructions
- Computer Organization | Performance of Computer
- Machine Instructions
- Construct a Turing machine for L = {aibjck | i>j>k; k ≥ 1}
- Turing machine for 1's and 2’s complement
- Construct Turing machine for L = {an bm a(n+m) | n,m≥1}
- Turing Machine as Comparator
- Construct a Turing machine for L = {aibjck | i< j< k; i ≥ 1}
- Construct a Turing machine for L = {aibjck | i < j < k or i > j > k}
- Turing Machine for addition
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

