Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmStack machine in Computer Organisation

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:

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments