Generic Stack Assembly Language Simulation
written by Teresa Carrigan
- What is it?
- How it works
- How to use it
- Things to notice
- Things to try
- Extending the model
- NetLogo features
- Related models
- Credits and References
- For more information
- Run model in your browser
- Download the model
- Single webpage version
WHAT IS IT?
This is a model of a generic zero-address computer, also known as a stack machine. The model animates the fetch-execute cycle as well as the stack. The user may choose to have the program show either the numeric contents of each memory location and item on the stack, or the algebraic expression. This allows students to test their stack machine programs to see if the programs correctly implement the assigned expression. When run from a website, the user may choose one of four sample programs, or may type in a program. When run from NetLogo, the user also may browse to select a program saved in a textfile. Please note that "BROWSE" does NOT work from an applet!
HOW IT WORKS
An assembly language program must be assembled, which constucts a symbol table. Memory locations mentioned in the program are shown on the right. The CPU contains a program counter, instruction register, CC register, stack, and a data path that connects the parts of the CPU with each other and to main memory (on the right).The fetch-execute cycle looks at the contents of the program counter to determine where to look for an instruction, then asks the bus to fetch the instruction in that location. The bus returns with the instruction, placing it in the instruction register. The program counter is incremented, so that it points to the next instruction, and the instruction in the instruction register is decoded to determine what to do with it. If the instruction mentions either a variable in the symbol table or a memory location, then the bus must fetch the operand. Finally, the instruction is executed. If the instruction is not a halt, then the cycle repeats.
A generic stack machine assembly language has only six operations: Push, Pop, Add, Sub, Mul, and Div. Push adds an item to the top of the stack, then increments the stack pointer. Pop removes the item at the top of the stack. This model also allows a Halt operation, to better illustrate the fetch-execute cycle.
HomeApplets 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.