Starting from:

$30

CS224-Lab 1 Creating and Running Simple MIPS Assembly Language Programs Solved

Preliminary Report/Preliminary Design Report:

Part 1simple array operations and arithmetic expression calculation. 

 

Lab Work:

Part 2  Using MARS with "hello world": Program1.asm.

Part 3 Using breakpoints, fixing errors in a Fibonacci program; using jal (jump and link) and jr (jump register) instructions.

Part 4 (Implementing an arithmetic expression given in lab. 

 

 

Part 1. Preliminary Work / Preliminary Design Report (40 points)

You have to provide a neat presentation prepared by Word or a word processor with similar output quality such as latex. At the top of the paper on left provide the following information and staple all papers. In this part provide the program listings with proper identification 

1. Write a MIPS program that

·        Initializes an array of maximum size of 20 elements: Do this by asking the user first the number of elements and then by getting the array elements one by one from the user.

·        Displays array contents.

·        Displays  the summation of array elements.

Note that maximum array size is fixed and 20 elements which can be achieved by a declaration like as follows 

                                             array:       .space   80

 

2. Write a MIPS program that implements the following arithmetic expression for integer numbers.

               x= a * (b - c) % d

In your program

·        Read a, b, c, d in the main program (main program: the part that the execution begins).

·        Pass a to d to a subprogram using the argument registers $a0, $a1, $a2, and $a3.

·        Perform the computation in the subprogram using $t (temporary) registers and return the result to the caller/main program in $v0.

·        Print the result in main.

·        In doing these provide a reasonable user interface for input and output.

 

Part 2, 3, & 4. Lab Work

Part 2. Using MARS, a MIPS simulator (15 points, A, B, C each part: 5 points)

A. Examine the controls and options in MARS

1.    Open the MARS simulator. Take a few minutes to explore each of the windows (Edit & Execute;  MARS Messages & Run I/O; Registers, Coproc 1 and Coproc 2). Look at each of the controls on the pull-down menus from the task bar at the top (File, Edit, Run, Settings, Tools, Help) and discuss what you think it does.  Change the run speed to 1 instuction/sec using the slide bar at the top. 

 

2.   Now, starting from the left, slowly put the mouse over each of the icons in the row across the top, to see the action that it will cause (but don’t click the icon).  Determine which actions, represented by the icons, also can also be selected from a pull-down menu. Click the “?” icon (or choose it from the Help pull-down menu) and in the Help window that open, click each of the tabs and briefly look at the Help contents for that topic. Note that the MIPS tab offers a box with scroll bar, and 6 tabs of its own. Similarly, the MARS tab opens a window with 8 tabs. Be sure to look at each of these.

 

3.    On the top menu, Tools offers a list of tools in the pull-down menu. Open each of these and look at it briefly to begin to understand the range of additional capabilities of MARS

 

 

B. Using a simple program in MARS

4.   Load in Program1 (Generates "hello world"), using File Open, or the appropriate icon button.  In the Edit window, examine this program, and learn what it does. Try to understand how it does it.

 

5.   Assemble the program, using Run Assemble , or the appropriate icon button.  In the Execute window, examine the code portion of memory (called Text Segment) and the data portion of memory (called the Data Segment). Note the beginning address of each, and the contents of each. Knowing that 2 hex characters represent one byte, and remembering  that ASCII characters are each coded as one byte,  determine which characters are stored in which locations in the Data Segment.  Examine the initial values of the registers—which ones are non-zero?  Make a note of their values. Read the messages in the MARS Messages window. Check the Run I/O window.

 

6.   Set the Run Speed bar to 1 instruction/second.  Now run the assembled program, using Run Go, or the appropriate icon button. What happens to the yellow highlight bar in the Text Segment during execution? What is written in the MARS Messages window? In the Run I/O window?  Compare the final values of the non-zero registers—did you expect to find $1, $4, and $2 changed by the program?  What is the final value of the $pc register?

 

7.   Now edit the Program1 so that it produces a different output:  Hello <name of your TA   Choose one of the TAs names or the Tutor’s name, and make it print out that name. Then call that TA or Tutor over to show your output.

 

C. Finding and fixing errors in MARS

8.   Load in Program2 (Conversion program), assemble it, and run it, providing the necessary input from the keyboard.  What does this program do? Examine the MIPS assembly program to understand how it does it.

 

9.  Edit the program by changing li $v0, 5 to li v0, 5 .  Then assemble it and read the error message. Then fix the error and re-assemble it.

 

10. Edit the program by changing li $v0, 5 to $li v0 .  Then assemble it and read the error message. Then fix the error and re-assemble it.  Now run the program, at 1 instr/sec, and make note of the value of $v0 after the 2nd syscall is completed.

 

11. Edit the program by changing mul $t0, $v0, 9 to mul $t0, $t0, 9 .  Then assemble it and run it, and explain why the output value is what it is. Then fix the error and re-assemble it and re-run it, to verify that Program2 again works correctly.

 

12.  Change the Run speed back up to the maximum. Assemble the program, and instead of hitting the normal Run button, instead hit the “Run 1 step at a time” icon (looks like 1) repeatedly, to single-step through the program.  Notice that you can go slowly, examining the memory and registers after each step, or go quickly. This single-step mode is good for debugging. Explain to the TA or Tutor how you could use it to help find a logical error or typo error that accidently passed the assembler’s syntax check.

 

Part 3. Using breakpoints in MARS, fixing logic errors and using jal and jr instructions 

 

Load in Program3 (Fibonacci program), which says it is a fibonacci number finder, implemented using a loop (iteratively, not recursively).  The program has several errors, syntax and logical, that you must find and fix.  After getting it to assemble correctly, note that it runs, but gives the wrong value of fib(7), which should be 13.  

 

To find and fix logical errors, you need to go through the code determining what the values are of the critical registers at the places in the program where they are changed.  In long programs, and especially programs with loops, it would take too long to single-step through the whole program. Instead, you must set breakpoints, and run up to those points and stop. Since the value of $v0 is where the fibonacci number is being accumulated in this program, you should set a breakpoint in the fib function wherever $v0 is changed. This way you can look at its value and determine if it is being caluclated correctly.  To set a breakpoint at an instruction, check the Bkpt box in the left-hand column next to the instructions you want to break at. Then hit Run.

 

 [Hint: if you are not sure if the state of the machine at the breakpoint will include the effect of that instruction or not, you should experiment and learn by setting breakpoints in pairs, both at an instruction of interest, and after it, to see when the actual change in values takes place].

 

When you have the Program3 debugged and running correctly, call the TA or Tutor to show how breakpoints work, and show that it calculates any Fibonnacci number. 

 

Part 4. Using MIPS for mathematical calculations Program 4
             

Write a program that prompts the user for one or more integer input values, reads these values from the keyboard, and computes a mathematical formula such as 

 

A= (B * C + D / B  - C  ) Mod B

 

 When the computation is finished, the program should print the result along with an explanatory comment to the user via the display. 

More products