CS224 – Creating and Running Simple MIPS Assembly Language Programs (Solution)

$ 29.99
Category:

Description

Lab Location: EA-Z04

Purpose: 1. Introduction to MIPS assembly language programming and MARS environment. 2. Learning CS224 lab rules and procedures.
You are obliged to read this document word by word and are responsible for the mistakes you make by not following the rules. Your programs should be reasonably documented -no exaggeration- and must have a neat syntax in terms of variable names and spacing as you have learned in CS101 and as suggested by the programs in the textbook.

Summary
Preliminary Report/Preliminary Design Report:
Part 3 (20 points): Using breakpoints, fixing errors in a Fibonacci program using jal (jump and link) and jr (jump register) instructions.
Part 4 (15 points): Implementing an arithmetic expression given in lab. Part 5 (20 points): Implementing a simple menu with loops.

b. Please upload your programs of Part 1 (PRELIMINARY WORK) to the Unilica by 13:30 on

No late submission will be accepted.

At the conclusion of the demo for getting your grade, you will upload your entire program work to the Unilica Assignment, for similarity testing by MOSS. See Part 6 below for details.

Part 1. Preliminary Work / Preliminary Design Report (30 points, contains sections 1 to 5 & each section 6 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 (please make sure that this info is there for proper grading of your work, otherwise some points will be taken off).
CS224
Section No.: Enter your section no. here
Lab No. 1
Your Full Name/Bilkent ID

1. Write a MIPS program that
Creates an array of maximum size of 20 elements that asks the user first the number of elements and then enters the elements one by one.
Displays array contents
Reverses the array contents and display the array (for example 1, 2, 3 becomes 3, 2, 1).

2. Write a MIPS program that
Gets a input string and checks if it is a palindrome. (Study load byte, store byte and some other instructions if need). Study the necessary syscall to read a string

3. Write a MIPS program that
Implements the following expressions without using div. If necessary use instructions other that we saw in the class.
x= (c – d) % 16

4. Generate the object code (in hex) for the following la and lw instructions. Show your work for the intermediate steps (both la and lw -in this form- are pseudo instructions and are implemented by two instructions).
la $t1, a
la $t2, b
lw $t2, b
lw $t2, b
…..
.data
.space 20
a: .word 1, 2, 3
b: .word 1

5. Define the following terms and provide an answer etc as described.
a. Symbolic machine instruction: give two examples
b. Machine instruction: give two examples and write their symbolic equivalents
c. Assembler directive: give two examples.
d. Pseudo instruction: give two examples and provide its implementation using real instructions. Note in your answer only use symbolic machine instructions.

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 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, tosee 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 itbriefly 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 Executewindow, 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, orthe 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?

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. Thenfix 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. Thenfix 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, andexplain 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.

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

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].

Part 4. Using MIPS for mathematical calculations Program 4 (15 points)
Write a program that prompts the user for one or more integer input values, reads these values from the

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.

Part 5. Using MIPS for implementing a program with a simple menu that involve loops Program 5 (20 points)
a. Find summation of numbers stored in the array which is greater than an input number.
b. Find summation of numbers within a value range specified two numbers and display that value.
c. Display the number of occurrences of the array elements divisible by a certain input number.
d. Display number of unique numbers in the array. For example, if the array contains 1, 2, 3, 1, 5, 2; the number of unique numbers is 4 and they are 1, 2, 3 and 5. e. Quit.
Optional: Use syscall with 9 in $v0 for dynamic storage allocation for the array.

Part 6. Submit your code for MOSS similarity testing
1. Submit your MIPS codes for similarity testing to the Unilica > Assignment specific for your section.
2. You will upload one file. Use filename StudentID_FirstName_LastName_SecNo_LAB_LabNo.txt
3. Upload only the programs.
4. Only a NOTEPAD FILE (txt file) is accepted.
5. Be sure that the file contains exactly and only the codes which are specifically detailed Part 1 to Part 6, including Part 1 programs (your paper submission for preliminary work must match MOSS submission). Check the specifications! Even if you didn’t finish, or didn’t get the MIPS codes working, you must submit your code to the Unilica Assignment for similarity checking.

Part 7. Cleanup
1. After saving any files that you might want to have in the future to your own storage device, erase all the files you created from the computer in the lab.
2. When applicable put back all the hardware, boards, wires, tools, etc where they came from.
2. When applicable put back all the hardware, boards, wires, tools, etc where they came from.
3. Clean up your lab desk, to leave it completely clean and ready for the next group who will come.

—————————————————————————————————————————–
Part 8. Lab Policies
1. You can do the lab only in your section. Missing your section time and doing in another day is not allowed.
4. You must be in lab, working on the lab, from the time lab starts until your work is finished and you leave.
5. No cell phone usage during lab.
6. Internet usage is permitted only to lab-related technical sites.
7. For labs that involve hardware for design you will always use the same board provided to you by the lab engineer.

1

Reviews

There are no reviews yet.

Be the first to review “CS224 – Creating and Running Simple MIPS Assembly Language Programs (Solution)”

Your email address will not be published. Required fields are marked *