Generic Stack Assembly Language Simulation

written by Teresa Carrigan


Run model in your browser


Top

THINGS TO NOTICE

Every time you Push an item, the stack gets one more item on top. For every time you Pop, Add, Sub, Mul, or Div, the stack loses one item.

What happens when you try to Pop and the stack is empty? What happens when you have a single item on the stack, and you try to Add? When you press Sub, how does the stack determine which item is subtracted?

When you push a number with a # in front of it, the number gets put on the stack without having to fetch an operand. When there is no # in front of the number, the bus fetches an operand that is the contents of that address, so the number pushed on the stack is probably completely different from what you get if there is #.

Notice that the program counter is incremented as soon as the operand is fetched, before the instruction is executed.

The CC register is updated after execution of each instruction. If the result is positive, then CC is changed to "P +"; if negative, then "N -" and if zero, then "Z 0".

Top

THINGS TO TRY

Load one of the demo programs, then click Run. Watch the fetch-execute cycle working with each line of the program, and what the commands do to the stack. Run the same program twice, once with "What-to-show" set to expression, and again with it set to contents. Write down the values of each variable before running the program, and the values after running, then check against the expression stored; does the program do the calculations correctly?

What happens when you divide and there is a remainder?

What happens when the top of the stack is a zero, and the next command is div?

What happens when there is a Halt command in the middle of a program?

Run a program, and in the middle of it click interrupt. When does the CPU notice the interrupt? When does it stop to handle it?

Write your own program, and test it using the model.


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.