Simple Stack Machine

written by Teresa Carrigan


Run model in your browser


Top

HOW TO USE IT

First press the Setup button, which builds the base of the stack. Now push at least two items onto the stack, and then try pressing one of the operation buttons. If you have written a Stack Machine program that you wish to test, then for each line of the program simply press the appropriate button. To see a demonstration of a random program, repeatedly press the "Random command" button.

Setup - Initializes variables and builds the base of the stack.

Push - Adds an item to the top of the stack. This requires the user to input the item to be added.

Pop - Removes the top item from the stack, storing it somewhere. In this simulation, it is simply displayed in the console.

Add - Removes the top two items from the stack, adds them, and then pushes their sum onto the stack.

Sub - Removes the top two items from the stack, subtracts them, and then pushes their difference onto the stack.

Mul - Removes the top two items from the stack, multiplies them, and then pushes their product onto the stack.

Div - Removes the top two items from the stack, divides them, and then pushes their quotient onto the stack.

Random command - Generates a single random line of a stack machine program, and then executes it. This is handy for demonstrating how the stack machine works when you do not have a program written yet.

Reset - Clears the command center window and also the graphics window. You must press Setup to build the stack again.


Home

Applets on this website were written by Teresa Carrigan in 2004, for use in computer science courses at Blackburn College, with the exception of the Fireworks applet. The applets made with NetLogo require Java 1.4.1 or higher to run. The applets made with NetBeans require Java 1.4.2 or higher to run. Applets might not run on Windows 95 or Mac OS 8 or 9. You may obtain the latest Java plugin from Sun's Java site.