MARS: An Education-Oriented MIPS Assembly Language
Simulator
Dr. Kenneth Vollmar Dr. Pete Sanderson
Missouri State University Otterbein College
Springfield, MO 65897 Westerville, OH 43081
417-836-5789 614-823-1317
[email protected] [email protected]
ABSTRACT Computing (JERiC) were devoted to computer architecture
We describe the implementation of “MARS,” a GUI, Java-based simulators for educational purposes [10][11]. The SPIM [5]
simulator for the MIPS assembly language. MIPS, the computer simulator is bundled with Computer Organization and Design
architecture underlying the simulated assembly language, is and described in its Appendix.
widely used in industry and is the basis of the popular textbook Our goal for this project was to create an alternative to SPIM
Computer Organization and Design [6], used at over 400 specifically for the needs of typical undergraduate students and
universities. The MARS simulator has been implemented with their instructors. It should be useful in courses such as computer
characteristics that are especially useful to undergraduate organization and architecture, assembly language programming,
computer science students and their instructors. and compiler writing. The resulting simulator is called MARS
(MIPS Assembler and Runtime Simulator) [8]. MARS is an
Categories and Subject Descriptors Integrated Development Environment (IDE) controlled by a
C.0 [Computer Systems Organization]: General – modern GUI whose features include:
Hardware/software interfaces, Instruction set design (RISC), • control of execution speed, including single step at variable
Modeling of computer architecture. speed (slider bar controls the number of instructions per
second)
General Terms • thirty-two registers visible at the same time, selectable via
Languages tabbed interfaces,
• “spreadsheet” (WYSIWYG) modification of values in registers
and memory,
Keywords • selection of data value display in decimal or hexadecimal,
Architecture, assembly language, simulation, MIPS
• resizable windows,
• “surfing” through memory using buttons to change display to
1. INTRODUCTION next/previous, stack location, global partition, and the start of
The MIPS RISC architecture and corresponding assembly the memory segment,
language use a limited number of instruction formats. Typical • toolbar icons for every menu item
student programs may use register-to-register, load/store, branch, • an integrated editor and assembler as part of its IDE.
jump, system call, and floating-point instructions. Thirty-two
general-purpose registers are available for integer operations
The MARS simulator implements the educationally important
(some have dedicated uses), as are thirty-two single-precision
portions of the MIPS instruction set utilized by Computer
floating point registers. MIPS is a clean design with simple
Organization and Design Third Edition (COD3) [6]. Specifically,
instructions, and is very popular in industry as well as academia.
the MARS simulator implements:
The widely-used Computer Organization and Design [6] text is
based on the MIPS architecture and instruction set. Since • All the instructions in the left-hand column of COD3 Figure
computer science and computer engineering departments may not 3.24, p. 226, which are the primary concentration of the text.
have adequate access to MIPS equipment to support laboratory • All the pseudo-instructions in the right-hand column of COD3
activities, software-based MIPS simulators may be used. Figure 3.25, p. 227.
Additional reasons for using simulation software in an
• All of the instructions in the right-hand column of COD3
organization and architecture course are described in [9], and two
Figure 3.24, p. 226 (MIPS arithmetic core) and left-hand
issues of the ACM Journal of Educational Resources in
column of COD3 Figure 3.25, p. 227 (remaining MIPS-32).
• The seventeen syscalls in COD3 App. A-48, including file
Permission to make digital or hard copies of all or part of this work for
personal or classroom use is granted without fee provided that copies are open, read, write, and close.
not made or distributed for profit or commercial advantage and that
copies bear this notice and the full citation on the first page. To copy
otherwise, or republish, to post on servers or to redistribute to lists,
requires prior specific permission and/or a fee.
SIGCSE'06, March 1-5, 2006, Houston, Texas, USA.
Copyright 2006 ACM 1-59593-259-3/06/0003...$5.00.
Figure 1. MARS editor window is active ( “Edit” tab is foremost).
Instructions not yet implemented in MARS include some pseudo- of the execute pane. These operations are illustrated and
instructions and other instructions expected to be more of described below.
professional than educational interest.
The MARS editor is an ASCII-oriented text editor that operates
The MARS simulator operates under either GUI or command-line much like Window's Notepad. Figure 1 shows the active editing
modes of operation. Students use primarily the GUI mode in pane. The first two groups of toolbar icons are used with the
either “go” or “single step” execution for assembly code creation editor. The first group corresponds to the File menu and includes
and debugging. Instructors have the option of running the file options such as New, Open, and Save. The second group
simulator from an OS shell or a batch command file, to facilitate corresponds to the Edit menu and includes operations such as Cut,
execution of several test cases of all student’s programs in Copy and Paste. Menu items and their corresponding toolbar
sequence for grading. Command-line arguments are used to buttons are enabled and disabled as appropriate.
request the output of particular registers or memory locations to
verify program results. To assemble the program, the user selects Assemble from the Run
menu or clicks the wrench toolbar icon. A successful assembly
The MARS simulator is written in Java 1.4.2, using standard causes the Execute pane to come forward as shown in Figure 2.
techniques of human-computer interaction via its Swing and AWT An unsuccessful assembly displays appropriate messages and line
packages. Standard icons have been obtained from the Java look numbers in the console window at the bottom of the screen.
and feel Graphics Repository [7].
The Execute pane contains several windows. The Text Segment
window is front and center. It displays both the source and binary
2. MARS OPERATION code of the assembly program, including the expansion of pseudo-
Students will typically use MARS to compose an assembly
instructions (the la and li instructions in Figure 2). A
language program using the editor, assemble it, then execute the
breakpoint can be set at any instruction using the check box in the
assembled program all at once or step-by-step using the facilities
Figure 2. MARS execution window is active ( “Execute” tab is foremost and the execution toolbar icons are active).
leftmost column. When stepping through program execution Another permanent display is the console window on the lower
manually or at reduced run speeds, the next instruction to be portion of the screen. It includes two tabs, one for MARS
executed is highlighted. messages such as assembly errors and another for runtime input
The Data Segment display illustrated at the bottom of Figure 2 and output generated by MIPS system calls. Each tab is activated
shows the program's data storage area in a scrollable window. Its when text is written to it.
lower border contains icons to control display of memory contents
at special locations such as the stack or heap, and check boxes to 3. SPIM AND OTHER MIPS
display memory addresses and values in either decimal or SIMULATORS
hexadecimal format. The contents of a memory word can be A number of MIPS simulators have been developed over the
directly edited at any time by double-clicking on its cell and years. Most can be classified by a small number of categories:
entering the desired value in either decimal or hexadecimal those designed for research use (e.g. MIPSI), those that focus on
format. certain MIPS architectural features such as pipelines (e.g.
Symbol table information is displayed in the Labels window. WebMIPS [2], SmallMIPS, RTLSim), those that depend on SPIM
This is relatively less important and the window may be closed to (e.g. MIPSASM, TinyMIPS), and general purpose simulators.
allow more space for the Text Segment display. Examples of the latter include MipsIt [3] and SPIM [5]. Most
MIPS simulators include features for visualizing and/or animating
Registers are permanently displayed to the right of the Execute
MIPS components. MARS and SPIM do not.
pane in a vertically oriented window. This can be seen in the
right side of Figure 1. As with memory, values are editable and The COD3 textbook and companion website refer to the SPIM
display format is selectable. There are separate tabs for the simulator, which is available on its bundled CDROM or from the
general purpose registers, the floating point registers of web. SPIM is without doubt the most widely known and used
Coprocessor 1 and the exception registers of Coprocessor 0. MIPS simulator, serving both education and industry. MARS has
been designed as an alternative to SPIM to meet the needs of
typical undergraduate courses. A comparison of some education- • a template of the generated 32 bit machine instruction with
oriented characteristics of SPIM 7.1 to MARS 2.0 follows. operand positions indicated
• a Java method to simulate the execution of the instruction
• The SPIM user interface has one window split into five
scrollable but non-resizable panes. Using PCSPIM on a 19”
monitor, at most nine lines of source code are visible at a All except the last are strings that may be placed in a textual
time. MARS uses resizable windows and tabbed panes to configuration file for loading when MARS is launched. Similarly,
more easily focus on memory, register or program contents. a separate text file is used to specify MIPS “pseudo-instructions”
• Several steps are required to modify register or memory values (a.k.a. macro instructions). Pseudo-instructions are expanded into
in SPIM: calling up a pop-up window, typing the register or one or more native MIPS instructions by the assembler. For each
address, and specifying the new value. This is time- pseudo-instruction, the text file contains a specification consisting
consuming and error-prone. MARS features WYSIWYG on- of an example usage followed by a tab-separated list of native
the-spot modification. instructions into which it will be translated with appropriate
• Similarly, SPIM’s breakpoints are set by calling up a pop-up operand substitution.
window and typing the breakpoint location. MARS features a These implementation features could be utilized by instructors
check box beside each line of code to set and remove and students to design and implement a customized MIPS-like
breakpoints immediately. instruction set, then use MARS to assemble and simulate
• SPIM permits simulated execution to proceed in "run", "single programs written in the new language. Custom simulated native
step" or "multiple step" mode. MARS permits the first two, and pseudo instructions are defined by adding the properly
plus offers a variable-speed timed mode (up to 30 formatted specifications into the configuration. Instructors in
instructions per second) with interactive display update, compiler writing courses may also use this capability to define
speed adjustment, and WYSIWYG value modification. See and implement a simplified target assembly language for student
slider in upper right of Figure 1. When set to maximum compilers.
speed, there is no interaction until the program terminates or
Because this capability was not part of the original design, the
the Pause or Stop button is selected.
assembler's tokenizer is not table-driven and thus any customized
• SPIM does not include an integrated editor, so files must be instruction set would have to follow MIPS lexical formats. This
edited by an external application. You may however easily is an issue we would like to address in the future. Nonetheless,
re-load such a file. MARS includes a basic text editor. we are very excited by the possibilities this capability presents in
the classroom.
In summary, support for interactive testing and debugging is one
of MARS greatest strengths. The tool plug-in capability permits the definition of customized
bots, animations, or any number of other useful tools to be
The MARS text editor currently provides Notepad-like controlled by a MIPS program during MARS simulation. A tool
functionality. Some contextual help is provided by tool tips that “observes” MARS memory locations and reacts appropriately in
appear when the mouse is hovered over the always-present response to data changes in the memory-mapped IO locations
Register window. Thus MARS provides limited support during defined for this tool. The source code of a tool is separate from
the program composition phase. This need can be addressed by the source code of MARS.
commercial editors such as Downcast Systems' MIPSter [4].
Using a dynamic class-loading technique from game programming
[1], any externally-compiled class which implements a certain
4. OTHER EDUCATION-ORIENTED Java interface and resides in the tools folder will be detected and
loaded at MARS launch and added to its Tools menu (see Figure
FEATURES AND DETAILS 1). User selection of that Tools menu item will invoke a particular
We have largely achieved our original MARS project goal, which interface method, which will typically establish itself as an
was to develop a viable alternative to SPIM for typical Observer of MARS memory locations. A MIPS program will
undergraduate use. In other words, to provide a tool that read and write memory locations and the tool will respond
implements the important MIPS instructions (those covered in accordingly.
COD3) through a portable and student-friendly IDE.
For instance, a “scrolling marquee” tool could graphically
Along the way, we realized that through MARS we could and simulate a rectangular array of LEDs in which an address
should achieve more significant contributions to assembly represents a vertical column of eight LEDs and an 8-bit data value
language and computer organization/architecture education. Here represents the on/off values of each of those LEDs. A MIPS
we introduce two aspects of MARS implementation that may program could implement a scrolling marquee on the LED array
represent its larger contribution: external instruction set by writing to two memory locations to specify LED address and
specification, and tool plug-in capability. Both are partially value. The tool has the responsibility of graphically displaying the
achieved at this time. LEDs, including the accurate modeling of LED illumination and
The simplicity and regularity of the MIPS instructions permit the persistence. The MIPS program has the responsibility of
separation of the specification of MIPS instructions from MARS determining the 8-bit values needed for the alphanumeric data,
source code. The specification for each instruction consists of: and refreshing the data in the memory-mapped IO locations at the
• an example usage of the instruction proper rate for the scrolling motion.
• the instruction format We have used this technique to implement a MARSBot similar to
[12] for display of the motions of a simulated robot. Interfacing
with physical hardware is possible using a tool which writes and The MARS jar file is available for downloading at
reads an external port of the MARS host computer. One of us has http://www.cs.missouristate.edu/~vollmar/MARS/.
proposed a sabbatical project to develop a virtual world using this
capability. 7. REFERENCES
[1] Brackeen, David, Barker, Bret, and Vanhelswue, Laurence,
5. STUDENT EVALUATIONS OF MARS "Developing Games in Java". New Riders Publishing, 2003.
Our computer organization students have used MARS for two [2] Branovic, I., Giorgi, R. and Martinelli, E., WebMIPS: A
semesters now. To rigorously assess our project goal of MARS as New Web-Based MIPS Simulation Environment for
a viable alternative to SPIM would require the same group of Computer Architecture Education, Workshop on Computer
students to be introduced to both simulators simultaneously and Architecture Education, 31st International Symposium on
equally – an unrealistic and ineffective use of class time. We Computer Architecture, Munich, Germany, 2004.
attempted to gauge student’s preferences between the MARS and
SPIM simulators by asking them to complete an anonymous, non- [3] Brorsson, M., MipsIt - A Simulation and Development
graded comparison of the use of SPIM 7.1 and MARS on one of Environment Using Animation for Computer Architecture
their own programs from earlier in the semester. We disclosed our Education, Workshop on Computer Architecture Education,
own involvement with MARS and asked the students to 29th International Symposium on Computer Architecture,
objectively compare the two. Anchorage AK, 2002.
In the survey that followed, students strongly preferred MARS to [4] Downcast Systems, MIPSter 2.0,
SPIM, citing most often user-interface aspects such as breakpoints http://www.downcastsystems.com/mipster/, retrieved 21
and icon control. The students’ description of simulator November 2005.
characteristics which contribute to the learning of an assembly [5] Larus, J., SPIM: A MIPS32 simulator,
language seemed to focus on single-step execution and convenient http://www.cs.wisc.edu/~larus/spim.html, retrieved 21
display of information pertinent to the current instruction. Most of November 2005.
the aspects of MARS for which improvements were requested
[6] Patterson, D., and Hennessy, J., Computer Organization and
have been implemented in MARS 2.0, including register display
Design: The Hardware/Software Interface, 3rd edition, San
layout, floating-point instructions, and hot key control of common
Francisco, CA: Morgan Kaufmann, 2004.
operations.
[7] Sun Microsystems, Java look and feel Graphics Repository,
6. AVAILABILITY AND FUTURE PLANS http://java.sun.com/developer/techDocs/hi/repository/,
We have ambitious plans for expanding MARS over the coming retrieved 21 November 2005.
year. As of this writing, MARS implements 98 MIPS32 native [8] Vollmar, K. and Sanderson, P., A MIPS Assembly Language
instructions, 36 pseudo-instructions, and the 17 system calls Simulator Designed For Education. The Journal of
described in COD3 Appendix A. We plan to continue Computing Sciences in Colleges, Vol. 21, No. 1, 2005.
implementing the remaining instruction set. Other plans include
improving debugging support through such features as [9] Wolffe, G., Yurcik, W., Osborne, H. and Holliday, M.,
highlighting of memory/register contents modified in step-by-step Teaching Computer Organization/Architecture With Limited
execution, and the ability to undo execution steps. Resources Using Simulators, ACM SIGCSE Bulletin 34, (1),
176 - 180, 2002.
As mentioned above, we plan to develop a virtual world that can
be controlled by an executing MIPS program, although the details [10] Yurcik, W. (guest editor), ACM Journal on Educational
have not yet been worked out. We would like to improve support Resources in Computing, Vol. 1, No. 4, December 2001.
for program composition through syntax highlighting and [11] Yurcik, W. (guest editor), ACM Journal on Educational
autocompletion a la MIPSter but this is a lower priority. A Resources in Computing, Vol. 2, No. 1, March 2002.
number of other features may be implemented or improved as
[12] Zilles, C., SPIMbot: an engaging, problem-based approach to
time and resources permit.
teaching assembly language programming. ACM SIGCSE
Bulletin 37, (1), 106 - 110, 2005.