This is a short guide on how to launch and use Mars. Mars will run on any system (including Windows) as long as you have Java installed. If you prefer, you may download and install Mars on your private computer.
Log in to the department Linux system. From the Applications menu you find Mars under Programming.
Mars should now start and you should see something similar to this.
Mars is an Integrated Development Environment (IDE) for Mips Assembly Language Programming.
At the top you find the top level menu: File, Edit, Run, Settings, Tools and Help.
Under the top level menu a collection of icons show some of the most commonly used tools and operations. The most important of these controls are described in the below table.
|Load a file.|
|Assemble the program in the Edit tab.|
|Save the current file.|
|Run the assembled program to completion (or breakpoint).|
|Execute a single instruction (single-step).|
|Undo the last instruction (single-step backwards).|
|Adjust the execution speed.|
In the middle left you find two tabs: Edit and Execute.
To the right you find the registers pane. Here the contents of all registers are shown. There are three register tabs:
In the lower left corner there are two tabs: Mars Messages and Run I/O.
The Mars Messages tab is used for displaying assembly or runtime errors and informational messages. You can click on assembly error messages to highlight and set focus on the corresponding line of code in the editor.
The Run I/O tab is used at runtime for displaying console output and entering console input as program execution progresses.
Before you continue you should already have cloned the
mips-examples repository. If you have not done this already,
follow these instructions before you continue.
Among the examples programs in the
misp-exmples repository you find
Open the file
hello.s in the Mars simulator by selecting Open from the File menu.
You should now see something similar to this.
After you loaded a program, the source code is available for edit in the Edit pane.
The default font colors might not be the most pleasing on your eyes. Especially the font color for comments may be hard to read. From the top menu, follow these steps to change the font colors:
To translate the Mips assembly source code to executable machine instructions an assembler is used.
You should see something similar to the following in the Mars Messages display pane.
Assemble: assembling /path/to/file/hello.s Assemble: operation completed successfully.
After a successful assembly, the generated machine code instructions together with the source code instructions are shown in the Execute pane.
In the the Run I/O display window you should see the following output.
Hello World! -- program is finished running --
From the Settings menu, select Show Label Window (symbol table). Now, the following window should appear.
The symbol table shows the actual memory addresses of all labels. For example,
we see that the label main is a mnemonic for the memory address
When you click on a label in the symbol table, the address of the label is
highlighted in the text or data segment.
In the symbol table, click on the label
Now the following row should be highlighted with a blue border in the Source
code column in the Text segment area in the Execute tab.
li $v0, 4 # Systemcall code print_str
If you look at the source code (press the Edit tab) you see that this is the
instruction following directly after the label
In the symbol table, click on the label
0x10010000 should be highlighted with a blue border in the
Data Segment area in the Execute tab. The value store at this address is
If you study the data segment in detail you see that the string
is stored byte for byte starting at address
A very usefull feature of Mars is the ability to set breakpoints. Breakpoints together with single-stepping and backward single-stepping are very powerful when trying to understand or debugging a program.
Make sure to view the Execute tab. In the Text segment, click the Bkpt
(breakpoint) checkbox at address
This will set a breakpoint on the
The execution will now halt at the breakpoint (the syscall instruction).
You are now ready to continue and study the
other example programs in the