Professional Documents
Culture Documents
5. References
Setting up JAVA SDK
(Please note this tutorial is to download JDK Ver 11)
Downloading Java SDK on macOS:
cd ~/Downloads
11. Extract the contents of the JDK archive using the following command:
tar -xvzf jdk-11.0.x_linux-x64_bin
Setting Up MARS Simulator
cd /Applications
10. Once you are in the correct directory, execute the following command to
run the MIPS MARS simulator:
11. The MIPS MARS simulator should now launch on your macOS computer.
fi
ffi
fi
Downloading MIPS MARS Simulator on Windows:
1. Open a web browser on your Windows computer.
cd "C:\Program Files”
10. Once you are in the correct directory, execute the following command to run
the MIPS MARS simulator:
11. The MIPS MARS simulator should now launch on your Windows computer.
8. This will extract the "Mars4_5.jar" file from the ZIP archive.
9. Move the "Mars4_5.jar" file to a suitable location on your computer. For
instance, you can move it to the /opt directory using the following command:
sudo mv Mars4_5.jar /opt
10. To run the MIPS MARS simulator, open the terminal and navigate to the
directory where you placed the JAR file. For example, if you moved it to the /
opt directory, use the following command:
cd /opt
11. Execute the following command to launch the MIPS MARS simulator
12. The MIPS MARS simulator should now launch on your Linux computer.
MARS ASSEMBLY AND SYSTEM CALLS
Before assembling, the environment of this simulator can be simplisticly split to three
segments: the editor at the upper left where all of the code is being written, the
compiler/output right beneath the editor and the list of registers that represent the
"CPU" for our program.
After assembling (by simply pressing F3) the environment changes, with two new
segments getting the position of the editor: the text segment where
i) each line of assembly code gets cleared of "pseudoinstructions" (we'll talk about
those in a sec) at the "basic" column and
ii) the machine code for each instruction at the "code" column,
and the data segment where we can have a look at a representation of the memory of
a processor with little-endian order.
After assembling, we can execute our code either all at once (F5) or step by step (F7),
as well as rewinding the execution several steps backwards to the back (F8).
• System calls are a set of services provided from the operating system. To use
a system call, a call code is needed to be put to $v0 register for the needed
operation. If a system call has arguments, those are put at the $a0-$a2
registers. Here are all the system calls.
• li (load immediate) is a pseudo-instruction that instantly loads a register with
a value. la (load address) is also a pseudo-instruction that loads an address to
a register. With li $v0, 4 the $v0 register has now 4 as value, while la $a0,
str loads the string of str to the $a0 register.
• A word is (as much as we are talking about MIPS) a 32 bits sequence, with bit
31 being the Most Significant Bit and bit 0 being the Least Significant Bit.
• lw (load word) transfers from the memory to a register, while sw (store word)
transfers from a register to the memory. With the lw $s1, 0($t0) command, we
loaded to $s1 register the value that was at the LSB of the $t0 register (thats
what the 0 symbolises here, the offset of the word), aka 256. $t0 here has the
address, while $s1 has the value. sw $t2, 0($t0) does just the opposite job.
• MARS uses the Little Endian, meaning that the LSB of a word is stored to the
smallest byte address of the memory.
• MIPS uses byte addresses, so an address is apart of its previous and next by 4.
MIPS Instruction Set
Pseudo instructions
Before looking at the instruction set , let us look at a few pseudo instructions that’ll
help you understand the IS better.
Given below are some standard arithmetic and logical instructions standard to
the MIPS Instruction Set Architecture.
MARS provides a small set of operating system-like services through the system
call (syscall) instruction
To request a service, a program loads the system call code into register $v0 and
arguments into registers $a0~$a3
System calls that return values put their results in register $v0
Arithmetic Instructions
shift left logical sll $1,$2,10 $1=$2<<1 Shift left by constant number of bits
0
Data Transfer
Conditional Branch
Unconditional Jump
jump and jal $ra=PC+4; go to address Use when making procedure call.
link 1000 1000 This saves the return address in
$ra
System Calls
Directive Result
.asciiz str Store the ASCII string str in memory and null-terminate
itStrings are in double-quotes, i.e. "Computer Science"
Registers
2.2) The buttons at the top of the window can be used as shortcuts for the run menu.
Use the “Reset” button to reset the program, and then try tracing through the
program by clicking the step button.
2.3) You can adjust the speed the program runs by moving the slider to the right of the
buttons. If you have an infinite loop in your program, it may be necessary to adjust
(slow down) the speed of the simulator to prevent the MARS program from
crashing.
Run the program. If a breakpoint has been set the
program will stop at the next breakpoint.
Trace (Step) Into. Executes a single instruction. If
the instruction is a procedure call (jal) the
simulator will stop at the first instruction of the
procedure.
Backstep. Undo the last step taken in the
code.
3.3) Run the program until the breakpoint by clicking “Run”. At this point in the
program only the first loop iteration has been printed. (You will need to click
back to the Run/IO window to see the output.)
3.4) Now use the “Trace Into” button to step through the loop that prints out the next line
of text one character at a time. Step through the instructions until “Loop #2” is
printed to the output window. Stop and find the value of the registers “t0” and
“pc” at that point? Has the line of code that the program counter points to executed
yet?
3.5) The simulator also allows you to view the memory contents. The memory window
appears in the middle of the screen and is titled “Data Segment”. Remove the
earlier breakpoint and add a breakpoint to line 33, “syscall”. Click the run button
so that the program executes up until the new breakpoint. We are now in the code
right before “Loop #” is about to be printed for the third iteration. Notice that the
$a0 register is now a pointer to the address where the “Loop #” text is stored. What
is the memory location the register is pointing to?
3.6) Now look in the data segment area, and find the address $a0 points to. This is the
memory section where the characters of the text “Loop #” is stored. Using an
ASCII table find the address where the ‘p’ in “Loop” is located?
3.7) Exercise: Can you find where the word “Welcome” is stored in the memory?
https://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html
https://courses.missouristate.edu/KenVollmar/mars/Help/MarsHelpIntro.html
https://riptutorial.com/mips/example/29993/mars-mips-simulator
https://bytes.usc.edu/ les/ee109/documents/MARS_Tutorial.pdf
fi