IFT 201 HW5
|
[IFT 201] |
Computer and Network Systems: Organization and Administration |
Lab 5: Processor Implementation
with MARS (MIPS Assembler and Runtime Simulator)
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 everyone’s favorite number sequence.
1. Start MARS
1.1 We can observe 3 main windows: Identify them
2. Use the menubar File…Open or the Open icon
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.1 The provided assembly program is complete. Assemble the program using the icon
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”. We’ll now identify the location and values of the program’s 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
· The
· The
· Use the slider bar to adjust the speed that the simulator runs at.
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, you’ll 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
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
A. 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_____ |
1. Start MARS, create a new assembler file (menu File > New), type in the program above and save the file as lab5.2a.s
2. Assemble the program
a. Provide the hex representation of the machine code corresponding to the MIPS assembly instruction: sw $t4, 200($t5)
b. What is the content of the PC register (in hex)?
c. At what address are the instructions labeled main, Loop, and Exit stored?
3. 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 |
|
4. 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 segment’s execution time.
B. 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: |
... |
|
1. 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)
2. 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.
C. 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
.
Part 3: Deliverables
Editing
Prepare your deliverable using this lab document as followed:
For Part-1:
1. Replace all the screenshots provided with your own screenshots
2. Insert your answers in a different color (for example, red or blue) to all the questions
For Part-2
1. Insert your answers in a different color (for example, red or blue) to all the questions in section Part-2A
2. Part-2B.1: Provide the complete code to be assembled
Part-2B.2: Provide the screenshots with the required annotations
3. Part-2C: Provide the complete code assembled, the required screenshot, and the answer to the question
Submission
1. Save your file as lab5_<YOUR USERNAME>.docx. Replace <YOUR USERNAME> with your ASURITE username. If you’re not using MS Word (for example, if you’re using Mac), please submit a PDF document.
2. Be sure to include your full name on every page. You can insert it in the header, above the “IFT 201” banner.
3. Upload your file to Blackboard.
Page 2