DOC

A Guide to the MARIE Machine Simulator Environment

By Bruce Simmons,2014-06-22 18:02
12 views 0
A Guide to the MARIE Machine Simulator Environment

    A Guide to the MARIE Machine Simulator Environment

    Accompanying The Essentials of Computer Organization and Architecture 2/e

     by Linda Null and Julia Lobur

Version 1.3.01 October 2006

Introduction

Your authors have made every effort to create a MARIE machine simulator that is as Really

    Intuitive and Easy to use as the MARIE architecture is to understand. We believe that the best way to gain a deep understanding of the MARIE machineor any computer system for that

    matteris to write programs for it. Toward our goal of helping you to understand how computers really work, we have created the Marie machine simulator, MarieSim. MarieSim is an environment within which you can write your own programs and watch how they would run on a real "von Neumann architecture" computer system. By running programs on this simulator, not only will you see your programs in action, but you will also get a taste of assembler language programming without learning any particular assembly language beyond the simple instructions that your authors have presented.

    MarieSim was written in the Java language so that the system would be portable to any platform for which a Java Virtual Machine (JVM) is available. Students of Java may wish to look at the simulator's source code, and perhaps even supply improvements or enhancements to its simple functions.

    As of Version 1.2, the MarieSim environment has also been provided with a datapath animator, called MarieDPath. We describe the operation of this simulator following our description of MarieSim operation.

Installation

    The software comes as a ZIP file. You must first unzip the .zip file. Upon doing this, you should have three .jar files (Java archive files), two .doc files (full documentation and a quick start guide), a README file, and three example MARIE assembly programs.

    The MARIE machine simulator requires Sun's Java 1.4.0 or later. This software is available at no charge from the java.sun.com Web site. There are two software packages for Java: (1) the JRE (Java run-time environment), which includes the Java Virtual Machine (JVM); and (2) the Java Development Kit (JDK), which includes the Java compiler. To run the simulator, you need the JRE software package. After this package is installed, you may run the simulator on Windows machines directly from the JAR files that have been provided. It is not necessary to unpack (unJAR) the MARIE machine simulator and its accompanying datapath simulator in order to run them. All that you need to do is double click on the MarieSim.jar icon to invoke the MARIE simulator, or the MarieDP1.jar file to invoke the datapath simulator. You may wish to copy, or drag and drop, the jar files to a convenient location on your system (such as the desktop). If you double click and the software will not run, check the information below on path and classpath.

    If you would prefer to run the Marie simulator (or datapath simulator) from the command prompt (which may be necessary on a Unix machine), you must manually unpack (unJAR) the class files. To do this, you must have the JDK software installed. The Java archive file MarieSim.jar (this is case sensitive) can be placed in the directory of your choosing. The following command will uncompress the archive:

     jar xvf MarieSim.jar

    1

    If the archive uncompresses correctly, you will have two class files (MarieSim1.class and MarieDP1.class) and some .mas files (sample assembly programs). Unjarring the files also creates two subdirectories, Meta-inf, and MarieSimulator. The MarieSimulator subdirectory contains all of the (many) other classes required for the simulator, the datapath, and the editor.

    If you also wish to see MARIE's source code, you can unpack the MarieSource.jar file that contains all of the Java source for the Marie simulator. This file is uncompressed in the same way as the simulator jar file:

     jar xvf MarieSource.jar

    The Java source will be uncompressed into the same directories as the class files.

To invoke the MARIE simulator (see Figure 1) from the command line, use the case sensitive

    command:

     java MarieSim1

    Note: On some machines, you may have to recompile the source before the simulator will run properly. You do this using the command:

     javac MarieSim1.java

    from the source directory where MarieSim1.java is located. (To compile, you need the JDK.)

    2

     Figure 1: The MarieSim Graphical Environment

Path and ClassPath Variables

    Regardless of whether you run the software by double clicking or you unpack and run from the command line, there are certain system variables that must be set. First, you must have your path set correctly (so your machine can find the Java command). On Windows machines, when you install the software, the path is typically updated. On Unix machines, you may have to edit the appropriate file to set your path (for example, the .cshrc file). If you try to run the software and get a ―command not found‖ error, then your path is most likely set incorrectly.

    To run the MARIE software, the Java classpath must be set correctly. The classpath is a user defined environment variable used by Java to determine where predefined classes are located. (Note: this is different from the path variable, which tells you where to find the Java command itself.) If you get an error saying that a particular class (such as ―main‖) cannot be found, then your classpath is most likely incorrect. If you run the software from the directory in which the files are located, the classpath should include a ―.‖, which indicates the ―current directory‖. To

    set the classpath on a Window’s XP machine, go to: Start | Control Panel | System | Advanced | Environment Variables, and look for ―classpath‖ in the upper window (do not edit system

    variables in the lower window!) Be sure that it includes a ―.‖. If there are other entries in the

    classpath, you can separate the different paths using a ―;‖. If there is no classpath entry,

    create one and enter only a single period as the value. NOTE: Do this ONLY if you are having problems running the software.

The MarieSim Environment

    Figure 1 shows the graphical environment of the MARIE machine simulator. The screen consists of four parts: a menu bar, a central monitor area, a memory monitor and a message area.

The central monitor area contains a program monitor area, six of MARIE's seven registers, and

    an output area, representing MARIE's seventh register. The memory monitor area displays the contents of all 4096 addresses of MARIE's memory. Each horizontal row of the memory area contains 16 memory addresses. Therefore, the address labels at the left side of the memory area are given in increments of 16, with titles above each column indicating the offset from the memory address of each row of memory. For example, the memory address DE8 is found in the column labeled +8 of the row labeled DE0. All addresses are given in hexadecimal.

    As the simulator executes your program, the instructions in the program monitor area are highlighted along with any memory in the memory area that the instruction is accessing. These highlights are most visible (on a fairly "fast" system) when you set a 500 millisecond (or greater) delay between instructions. (See below). With a little experimentation, you will find an optimal value for your system.

    During the course of executing your program instructions, status messages may appear in the message area at the bottom of the screen. When your program ends, you will see either a "Program halted normally" or "Program halted abnormally" message. If you never see this message, either your program hasn't started running yet, or it is in a loop and you'll need to halt it manually.

The MarieSim Controls Menu

    3

    The menu at the top of the simulator gives you control over the actions and behavior of the MARIE machine Simulator system.

The File Menu

The features available through the File menu are shown in Figure 2. If you already have an

    assembled MARIE program at your disposal, all you need to do is load it and run it. If you want to write a program from scratch, you should select the File | Edit option. The Edit option

    gives you a simple way to write and assemble programs in MARIE assembly language.

    Figure 2: MarieSim File Menu Options

    Although you can use any plain text editor (perhaps one with fancier features) to create your source code, the simulator's built-in editor gives you one-button access to the assembler. The MARIE editor frame is shown in Figure 3.

    4

Figure 3: The MarieSim Editor

5

The MARIE Editor

    Once you select File | Edit, and if you do not have a file loaded in the simulator (as shown in Figure 3), the editor frame is displayed with a blank text area. If, however, you have already loaded an assembled file into the simulator, the source code for that file is automatically brought into the editor if the editor can locate it.

MARIE assembly code source files must have an ".mas" extension, for MARIE Assembler. Both

    the editor and the assembler recognize files of this type. Once you have saved a file with an ".mas" extension, the Assemble menu option becomes enabled and you can assemble your

    program by selecting the Assemble current file menu pick. If you load an existing ".mas" file, the

    Assemble button is automatically enabled. Any modifications that you have made to your to your assembly-language file are automatically saved by the editor prior to its invoking the assembler. This process is shown in Figure 4, using the example from Table 4.5 in the text.

    Figure 4: Preparing to Assemble Source Code

    If the assembler detects errors in your program, the editor sends you a message and the assembly listing file appears in a popup frame as shown in Figure 5. All that you need to do is correct your program and press the Assemble current file button once more. If the file contains

    no other assembler errors, you will see the screen shown in Figure 6. If you wish, you can display or print the assembly listing file, by using the editor or any text-processing program.

    The listing file will be placed in the currently-logged directory, along with the "MARIE machine code" file, if assembly was successful. The listing file is a plain-text file with an ".lst" extension. For example, when Fig4_5.mas is assembled, the assembler produces Fig4-5.lst. You may view it, print it, or incorporate it into another document as you would any plain text file. If assembly is error-free, a ".mex" or MARIE EXecutable file will also be placed in the same

    6

    directory as the source and listing files. This is a binary file (actually a serialized Java object) that is executable by the simulator.

    Figure 5: An Unsuccessful Assembly

    For example, if your assembly source code is called MyProg.mas, the listing file will be called MyProg.lst and the executable will be called MyProg.mex.

    Once you have achieved a "clean" assembly of your program, you will see the message shown in Figure 6. If you are satisfied with your program, you can exit the editor by closing its window or selecting File | Exit from the menu.

    As implied above, the MARIE editor provides only the most basic text-editing functions, but it is tailored to the MarieSim environment. The Help button provides you with some general help,

    as well as an instruction set "cheat sheet" that you can use for reference as you write your programs.

    The frame in which the editor appears may look a little different on your system, but you can manipulate it as you can with any frame, that is: you can maximize it, minimize it, hide it or close it. This is true of all frames spawned by the editor as it responds to your commands.

    7

    Figure 6: A Successful Assembly

Loading Your Program

    After you have successfully assembled your program, you must load it into the simulator by selecting the File | Load menu option from the simulator. This option brings up a file chooser panel that lists all of the MARIE executable files in your current directory, and the names of other directories that are available to you. All you need to do is highlight or type the name of the file that you wish to run.

Note: Each time you reassemble a file, you must reload it.

    8

    Figure 7: A Program Ready to Run

    Figure 7 shows the MARIE simulator after an executable file has been loaded. The program monitor window shows the assembly language statements as they were written, along with their hexadecimal equivalents. At the left-hand side of the program monitor, you will see the addresses of the program statements. The statement that has just been executed by the simulator is shown in green highlight, so that you can see the effect that the instruction has had upon the state of the machine. Of course, when the program is first loaded, the green highlight will be on the statement at the first address of your program. You will also notice that the PC register is set at the address of the first statement in your program, indicating that this is the next statement that will be run.

    Keep in mind that the program monitor window is there only to help you visualize what is going on. The program instructions are, in reality, pulled from the memory panel at the bottom of the screen. Once you have loaded your program, you will notice that the memory monitor contains the hexadecimal program instructions in the addresses corresponding to those in the program monitor window. A green highlight will move to different memory location as your program runs, accessing various storage locations.

    Once loaded, your program can be executed using any of three different run options.

The Run Menu

    The Run menu offers a number of features that allow you to have control over how your program is executed by the simulator. As shown in Figure 8, the first option on this menu is

    Run | Run, which executes the statements in your program in sequence to termination. When you select Run | Run, the Stop button becomes enabled, giving you the chance to halt your

    program should it get stuck in a loop or simply is taking too long to run.

    9

Figure 8 shows the Run menu option that you would use to put your program into step mode.

    Step mode allows you to execute your program one statement at a time. After executing each statement, the simulator pauses until you press the Step button (or the program terminates).

Note: If the simulator is in step mode, and you subsequently select Run | Run, the simulator

    automatically terminates step mode and enters run mode.

    Figure 8: The Run Menu

The Run | Set Delay Option

    By default, the MARIE simulator pauses for approximately 10 milliseconds between subsequent executions of program statements when it is in run mode. The main purpose for this delay is to allow you to halt execution of your program, should you desire to do so. The delay feature may also be used to allow slow-motion viewing of your program statements as the simulator executes them. You can put the simulator in this slow-motion mode by setting the delay to 500 milliseconds or longer.

    The delay-setting screen is shown in Figure 9. To change the execution delay, just move the slider bar to the desired number of milliseconds and press the Okay button.

    Setting the slider: As you would expect, you can move the slider pointer by clicking and dragging it with your mouse. You can also move it using the cursor-movement keys on your keyboard. Page Up and Page Down move the slider by large increments, and your left and right arrows move it by smaller increments, allowing for precision setting of the slider bar.

    10

Report this document

For any questions or suggestions please email
cust-service@docsford.com