Question
Lab 9: Processor Implementation with MARS (MIPS Assembler and Runtime Simulator) 50 pts MARS is a tool for students to explore the MIPS architecture, which
Lab 9: Processor Implementation
with MARS (MIPS Assembler and Runtime Simulator) 50 pts
MARS is a tool for students to explore the MIPS architecture, which is jointly developed by Pete Sanderson (Otterbein University) and Ken Vollmar (Missouri State University).
Download and Install MARS
MARS may be downloaded from www.cs.missouristate.edu/MARS.
From the menu on left, click "Download"
Download and install Java J2SE SDK (currently: JDK 8u60)
Download latest version of Mars (currently v4.5) and save on your desired location
Go back to MARS website and download the file "Fibonacci.asm" and save in the same location
Double-click on "Mars4_5.jar" file to start MARS
Part 1: Basic MARS Use
The example program is Fibonacci.asm to compute everyones favorite number sequence.
1.Start MARS
1.1We can observe 3 main windows: Identify them
2.Use the menubar FileOpen or the Open icon to open Fibonacci.asm in the default folder. (All icons have menubar equivalent.)
Examine the code carefully. The MIPS assembly language has a few simple rules:
MARS accepts files with either .asm or .s extensions
Text that follows after a pound sign (#) is a comment.
A line that starts with a period (.) is an assembler directive. Assembler directives are a way of instructing the assembler how to translate a program but do not produce machine instructions. For example, .globl main defines main as a global variable.
Text followed by a colon (:) defines a label. It is similar to defining variables in any high-level language.
2.1The provided assembly program is complete. Assemble the program using the icon or from the menu, click Run > Assemble
The Mars Messages window at the bottom of the screen will indicate if any errors occurred. You should have a screen below after successful assembly. Provide your screenshot
2.2 The simulator allows you to view the memory contents. The memory window appears in the middle of the screen and is titled Data Segment. Well now identify the location and values of the programs initialized data. Use the checkbox to toggle the display format between decimal and hexadecimal
The array fibs is an array of 12 words starting at address 0x10010000. What is the address of the last element of the array? What are the initial values?
What is, in decimal, the value stored at address 0x10010030?
3.Use the Settings menu to configure the MARS displays. The settings will be retained for the next MARS session.
The Labels display contains the addresses of the assembly code statements with a label, but the default is to not show this display. Select the checkbox from the Settings menu.
Select your preference for allowing pseudo-instructions (programmer-friendly instruction substitutions and shorthand).
Select your preference for assembling only one file, or many files together (all the files in the current folder). This feature is useful for subroutines contained in separate files, etc.
Select the startup display format of addresses and values (decimal or hexadecimal).
Select Memory Configuration then Compact, data at address 0
What are the addresses of the variable size and the array fibs?
4.Locate the Registers display, which shows the 32 common MIPS registers. Other tabs in the Registers display show the floating-point registers (Coproc 1) and status codes (Coproc 0).
4.1 What is, in Hexadecimal, the content of register $sp?
4.2 The program counter (pc) is a special register containing the address of the next instruction to be executed. What is, in Hexadecimal, the content of the program counter?
4.3 Give the assembly code for the instruction the program counter is pointing to
5.Simulate the program:
From the menu, choose Run > Go to execute the program. The program will execute, displaying a sequence of Fibonacci numbers to the Run I/O window.
You can also use the shortcut buttons:
The icon runs the program to completion. If a breakpoint has been set, the program will stop at the next breakpoint
The icon resets the program and simulator to initial values. Memory contents are those specified within the program, and register contents are generally zero.
The icon is single-step. Its complement is , single-step backwards (undoes each operation).
Use the slider bar to adjust the speed that the simulator runs at. This allows us to watch the action instead of the assembly program finishing directly.
5.1 Observe the output of the program in the Run I/O display window.
Write the output here, exactly as shown
6.Using the Debugging Tools
When a program does not work as expected, youll need to use the debugging tool provided with the simulator
One of the primary tools used to debug a program is setting a breakpoint. You can break before execution of an instruction by clicking on the checkbox associated with each instruction on the far left of the Text Segment window.
Example: set a breakpoint at the instruction whose address is 0x0040005c. Note that you may not have the same address; so locate the associated instruction on your code and set the breakpoint.
Reset and re-run the program, which stops at the breakpoint.
Provide, in hexadecimal, the content of the below elements of the array fibs:
fibs[10] =
fibs[11] =
Part 2: Assembly Program segments
For all the programs in this part, use the following template:
.text
main:
# The program code here
# The program code here
addi $v0, $zero, 10
syscall
Consider the following program segment for the MIPS architecture.
main: | addi | $t0, $zero, 100 | |
Loop: | slt | $t3, $t1, $t0 | _________ |
beq | $t3, $zero, Exit | ||
add | $t4, $t1, $t1 | ||
add | $t5, $t4, $t4 | ||
sw | $t4, 200($t5) | ||
add | $t2, $t2, $t4 | ||
addi | $t1, $t1, 1 | ||
j | Loop | ||
Exit: | ____1_____ |
Start MARS, create a new assembler file (menu File > New), type in the program above and save the file as lab5.2a.s
Assemble the program
Provide the hex representation of the machine code corresponding to the MIPS assembly instruction: sw $t4, 200($t5)
What is the content of the PC register (in hex)?
At what address are the instructions labeled main, Loop, and Exit stored?
Run the program by clicking Simulator > Run. Provide the contents of the registers used and the PC
Register | Final Value |
$t0 | |
$t1 | |
$t2 | |
$t3 | |
$t4 | |
$t5 | |
PC |
In the space provided to the right of the instructions labeled Loop and Exit, enter the number of times these instructions are executed during the program segments execution time.
Consider the following program segment (which consists of all instructions shown) for the MIPS architecture discussed in class. Initial values in registers pertinent to this problem are: $a0 = 4 and $t0 = 4032; the values in memory location 1232 is 4000; values are in decimal.
Beg: | lw | $t6, 1232($zero) |
Top: | beq | $zero, $zero, Nex |
Sec: | sw | $s7, 0($t6) |
beq | $zero, $zero, End | |
Nex: | lw | $s7, 0($t6) |
add | $t6, $t6, $a0 | |
Key: | beq | $t6, $t0, Sec |
beq | $zero, $zero, Top | |
End: | ... |
Modify the program above, incorporating the code below so that the initial values are set in registers and memory location before the instruction labelled Beg is executed. Save the resulting file as lab5.2b.s
addi $a0, $zero, 4
addi $t0, $zero, 4032
addi $s0, $zero, 4000
sw $s0, 1232($zero)
Assemble your new code
Set a breakpoint on the instruction labelled Beg
Run the program and verify those initial values. Take screenshot(s) showing (use a colored pencil to circle) the values in registers $a0 and $t0, and in memory location 1232.
Consider a list (aka an array) A of 10 elements defined as followed:
A = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
The MIPS assembly code below loads the contents of the list A into memory starting at the address stored in register $s0.
The initial values in register $s0 is 100.
Assemble and run the program. Take a screenshot of your text segment and data segment, showing the array elements above in memory. What is the address of the last element of the array?
addi $s0, $zero, 100
addi $t5, $s0, 40
TOP: addi $s5, $s5, 10
sw $s5, 0($s0)
addi $s0, $s0, 4
bne $s0, $t5, TOP
Consider execution of the following program. All registers used contain 0 initially.
Beg: | or | $15, $16, $17 | ||
add | $16, $15, $17 | |||
DTI: | lw | $17, 1232($0) |
The registers are represented by their corresponding numbers in the MIPS architecture. For example, register $zero is written as $0.
Assume that before the instruction labelled Beg is executed the state of the system was as followed:
The values in memory location 1232 is 4000
Every register used (except $0) has initial value 10ten plus the register number (e.g. $8 has initial value 18ten)
The code to set the initial state of the system is provided below:
addi $15, $0, 25
addi $16, $0, 26
addi $17, $0, 27
addi $10, $0, 4000
sw $10, 1232($0)
Ensure your MARS setting is as instructed in Part I.3
Modify the program segment so that the initial values are set in registers and memory location before the instruction labelled Beg is executed, by incorporating the code provided to set the initial state of the system
Assemble your new code
Set a breakpoint on the instruction labelled Beg
Run the program and verify those initial values. Take screenshot(s) and circle those values to show
Go to Tools > MIPS X-Ray
Click on Connect to MIPS
Run the instructions one step at a time from the MIPS R-Ray window
Watch the execution of each instruction carefully on the animated screen.
Provide the screenshots of the X-Ray window for each of the 3 instructions above (or, add, and lw).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started