MARS Primer
Some things you need to know about MARS
- Just under the toolbar are two tabs labeled "Edit" and "Execute"
- in the Edit window you can type in your program and make changes to it
- in the Execute window you can run your program and inspect the state of the machine
- breakpoints (details below)
allow you to make the program stop right before any instruction that you choose
- you can also run the program one instruction at a time using the single-step button
- you can even single step backwards
- Down near the bottom are two tabs labeled "Mars Messages" and "Run I/O"
- MARS will print assembly results (success, errors) in the Mars Messages window
- when your program prints things, they will appear in the Run I/O window
- the Execute window has several subwindows that you need to be familiar with:
- the text-segment window is at the top left;
it displays the instructions in your program, one per line and in five columns:
- the first column contains checkboxes;
each checked box marks the instruction on that line as a breakpoint;
when the program encounters a breakpoint,
it will stop just before fetching and executing that instruction
- the second column displays the memory address of the instruction on that line
- the third column displays the assembled instruction in hexadecimal
- the fourth column displays the instruction source with fakes replaced by real code
- the fifth column displays the instruction source as you typed it but with macros expanded
- when the fourth and fifth columns differ in any material way,
that is a sure sign that you are looking at a fake of some kind
- usually, when this is the case, the fourth column will have more lines than the fifth column
- the data-segment window is right under the text-segment window;
it displays the data segment of your program in nine columns
- in each row, the first column contains an address;
each of the other eight columns contains one data word
- the address in the first column is that of the first data word
in that row (the one in the next column)
- as you move from left to right across a row,
each column's address is 4 more than the column before it
- this is indicated by the column headers in the very first row
- the address of each cell is the sum of the number in that row's address
column and the number in that column's header
- each word is made up of four bytes
- each word is made up of eight hex digits, so each byte is made up of two hex digits (4 bits each)
- the bytes appear in right-to-left order in their word because MARS is little-endian
- the registers window is at the far right
- each register is identified by name and by number and its contents are displayed
- when you single-step through a program, the last register changed is highlighted in green
- watching to see that registers change as you expect them to is a principal debugging technique
- the labels window is between the text-segment window and the registers window
- to see it, you must choose "Show Labels Window", which is the first item in the Settings menu
- it displays the value assigned to each of the labels in your program
- each of these values is an address
- they can change as you make changes to your program; stay alert to this
- addresses in the data segment begin at 0x10010000
- addresses in the text segment begin at 0x00400000