lab02.Handout (1)

docx

School

University of California, Berkeley *

*We aren’t endorsed by this school

Course

210

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

7

Uploaded by CaptainThunderGoldfish14

Report
Kettering University Computer Architecture and Organization Lab Exercise 2 Analysis of MIPS Programs MIPS & SPIM (Cont’d) Winter 2023 Note Tests/final may contain questions about lab exercises. Lab report : Upload one handout (report) per group (in .pdf ) to Blackboard before 11:59 pm on the coming Sunday and after completing all the assignments, answering all the questions, and showing your lab work to the lab instructor individually . A demo sign-up sheet will be posted if necessary. Name : Lab Partner’s Name : Purpose of this lab exercise (please use your own words)
CE-422/622 Computer Architecture and Organization Lab Exercise 02 Objectives Gain hands-on experience with more MIPS instructions as well as MIPS programming styles. Get hands-on experience in program analysis. Practice writing good comments. Learn more about spim . What to hand in Upload this handout in .pdf after completing all the assignments and answering all the questions. Show your functional codes to the lab instructor. Also, be prepared to individually answer the lab instructor’s questions rearguing today’s lab exercise and what your group did. You should work closely with your lab partner. You are also urged to talk to other students, teach them or learn from them, as this will enhance your performance; however, do NOT copy from them! Introduction We may also analyze programs and design programs similar to hardware analysis and hardware design. In today’s lab, you will analyze two programs written in MIPS assembly language and then simulate them using spim to verify your findings. More about SPIM, single-stepping, and breakpoints: You used single-stepping in lab01 and learned how to execute one instruction at a time to debug/test your programs. Remember that after each instruction execution, you can examine the registers and memory locations to see if the implementation is consistent with your expectation. Use F5 to run the whole program nonstop for demonstration purposes, but now you need to put a breakpoint on the instruction right after your program's last instruction. Spim will stop only when it reaches that instruction. To place a breakpoint on an instruction, point to that instruction, then right-click; a window will pop up with four choices. The last two are Set Breakpoint and Clear Breakpoint . You may also combine breakpoints and single-stepping for debugging purposes: use a breakpoint to quickly reach a questionable region in your program and then use single-stepping to locate the first problematic instruction. Write good comments! Add only explanatory and short comments to the instructions in your programs. Your comments should provide as much information as possible. So, if in a program, $s4 is a loop counter , do NOT write a comment like this: # add 1 to $s4 for the following instruction addi $s4, 1 Because it is obvious! It does not provide more information than the instruction itself does. A good comment would be: # Update loop counter Guideline: Avoid using the registers’ assembly names, such as $s4 , in your comments as much as possible. Instead, use meaningful/descriptive names that you assign to the registers. Page 2 of 7
CE-422/622 Computer Architecture and Organization Lab Exercise 02 Page 3 of 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CE-422/622 Computer Architecture and Organization Lab Exercise 02 Assignments 1. Analyze the following MIPS assembly code carefully and determine what the code carries out. Also, add an explanatory and short comment to each line of code, if necessary. You may assume that $s0 initially contains n = 13 , but the program works fine for any reasonable n . Remember that ‘#’ is the comment sign . Hint : First, determine how $t1 changes. main: addi $t0, $zero, 0 # addi $t1, $zero, 1 # get the first odd number loop: slt $t2, $s0, $t1 # bne $t2, $zero, finish # add $t0, $t0, $t1 # addi $t1, $t1, 2 # j loop # finish: add $s1, $t0, $zero # nop # NOP does nothing! Briefly but clearly describe what this code carries out. Which registers are input(s) and output(s)? What are their final contents? Let us assume that $S0 is initially set to 13. Do not describe the details ! Your description should be in the following compact format : Example: The code adds up all the bytes in a null-terminated array pointed to by $s7 and places the sum, decimal 159, in $s5. In a new directory called lab02 in your Architecture folder, type (or copy ) the above code in a text file. Set $S0 to 13 and run the code using single-stepping. (You may also try different numbers.) Is the result what you were expecting? When the code works correctly, set a breakpoint on the nop instruction (in the above code), and run the code in one step using the RUN key (F5). Show your functional code to the lab instructor. *** To simulate the second code in Assignment 2., we need a word array of data, which can be created and initialized using the following assembler directives : . data A : . word 8, 2, 6, 12, 8, 7, 6, 2, 6, 5, 6 # put a space after each comma # Place the code segment right after the data segment in the same file: . text main : Page 4 of 7
CE-422/622 Computer Architecture and Organization Lab Exercise 02 2. The following MIPS assembly code processes an 11-word array and produces two important values in registers $s2 and $s 3 . Register $s0 points to the base of the array, and the array size (11 words) is initially in $s1 . Go over this code carefully and determine what the code carries out. Also, add an explanatory and short comment to each line of code, if necessary. Remember to give a meaningful name to each register used in this code if they are not already named: # This is the data segment . data # Define and initialize a word array called A: A : . word 8, 2, 6, 12, 8, 7, 6, 2, 6, 5, 6 # This is the code segment . text main: la $s0, A # l oad a ddress, pseudo instruction: $s0 becomes array’s base pointer. li $s1, 11 # l oad i mmediate, pseudo instruction: set $s1 to array size. add $s1, $s1, $s1 # add $s1, $s1, $s1 # add $s2 , $zero, $zero # add $t0, $zero, $zero # outer: add $t4, $s0 , $t0 # initialize outer pointer lw $t4, 0($t4) # read next outer word add $t5, $zero, $zero # add $t1, $zero, $zero # reset inner offset inner: add $t3, $s0, $t1 # initialize inner pointer lw $t3, 0($t3) # read next inner word bne $t3, $t4, skip # addi $t5, $t5, 1 # update hit counter skip: addi $t1, $t1, 4 # bne $t1, $s1, inner # slt $t2, $t5, $s2 # bne $t2, $zero, next # add $s2, $t5, $zero # update current max add $s3, $t4, $zero # next: addi $t0, $t0, 4 # bne $t0, $s1, outer # nop Page 5 of 7
CE-422/622 Computer Architecture and Organization Lab Exercise 02 Briefly but clearly describe what this code carries out. Which registers are input(s) or output(s)? What are their final contents? Note : Do not explain the details! In the lab02 directory, type (or copy) the code in a text file. Run the code using single-stepping. Is the result what you were expecting? When the code works correctly, set a breakpoint on the nop instruction (in the above code), and run the code in one step using the RUN key (F5). Show your functional code to the lab instructor. Question: What pseudo instruction can you replace the following two true instructions with? slt $t2, $t5, $s2 bne $t2, $zero, next Question: Briefly but clearly explain what would happen in general if these two code lines slt $t2, $t5, $s2 bne $t2, $zero, next were replaced with the following two code lines: slt $t2, $s2, $t5 beq $t2, $zero, next Page 6 of 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CE-422/622 Computer Architecture and Organization Lab Exercise 02 Think Critically Is a good algorithm used in this program? Highlight Yes or No . Briefly but clearly comment on your answer : Page 7 of 7