Executing Programs

Executing code in the virtual machine.

Executing Programs

This application is meant to be a learning tool for understanding compilers and virtual machines. As such there are many features included here that are not found in a simple implementation of the VM. The views and machine are intended to be as interactive as possible to help the student understand what is going on as a program executes.

Contents

Executing Instructions

Adding Notes

It is often convenient to annotate memory with something to help you remember what it represents or or how it got created. If you click in a Notes cell in the Stack View section you will be prompted with a dialog to edit the Note for that memory location.

Annotated Memory

Editing registers

At any time during the execution of a program you can manually override any of the registers. Simply click on the register title and enter in the new value at the prompt. There are no guarantees that the VM will behave well. Use this feature to stress the machine or set up unusual situations and see how they play out. No one will be harmed. It's just a virtual machine in your web browser after all.

Adjusting viewable size

Some of us are lucky and have large screens. This application was developed on my 27" iMac and I was loving every minute of it. I sized the panels so they worked very well with my display. However trying this out on my little 13" work MacBook, the app was unusable. So I added a feature with which you can change the size (depth) of the Program Store, Stack and Heap panels. Just use the control at the very top of the screen to change the size of these panels (in pixels). I found that with a combination of 80% view of my browser window and a panel size of 400px the app was usable on my smaller 13" screen.

Copy Stack to Clipboard

A useful feature I added in late was a copy to clipboard button on the Stack View. This was to facilitate the completion of assignments in the text that asked for the stack to be displayed after each instruction. At any time you can click on the icon in the Stack View title to copy the contents of the Stack View into the clipboard. The entire main memory is not copied, but rather all the contents of the stack from the EP register and below. This way the resulting table is only concerned with the values in the stack that are legal.

There are two forms of the stack placed in the clipboard, an HTML formatted view with shading. This is useful for pasting into apps like Microsoft Word.

Copying the stack in MS Word

And a text only view with formatted spaces for documents that have fixed space characters.

Text view of copied stack

Redefine VM Memory

By default the virtual machine that gets created has 64 memory locations (the term byte or word is irrelevant in this virtual machine). You can set the main memory size to anything up to 1024 (an arbitrary upper limit I set) with the control at the very top of the screen. The program size however will expand to whatever size of program you feed it.

Breakpoints

You can set a breakpoint in the code by clicking just to the left of the instruction row in the Program Store. A small bullet icon will appear. Clicking on it will toggle the breakpoint off. When you set a breakpoint and you press the Run to Brkpt command the code will execute quickly (updating the display alone the way) until a breakpoint is reached or the program is halted, or an error is thrown by the virtual machine.

Breakpoint set on print instruction