menu

Lab2 Due Sept 5 2019

Create a local folder called CS210Lab2YourName. Use this folder to save all the artiacts of this lab. When finished submit the folder as a zip file (CS210Lab2YourName.zip).

  • Loops

    Compare factorial program implemented with recursion and loop

    1. Create a local folder called CS210Lab2YourName. Use this folder to save all the artiacts of this lab;
    2. Use the following programs as examples: fact.s loop.s while.s
    3. Load fact.s in QtSpim
    4. The program does not look exactly the same as in the fact.s file. However, the real code is displayed as comments. Answer the following questions and perform the described tasks:
      1. Why is the program in SPIM different?
      2. What do the instructions LI and LA mean?
      3. How are they translated to bare machine instructions?
      4. What is the starting address of the 'main' routine?
      5. What is the starting address of the 'fact' routine?
    5. Single-step the code from start until it reaches the first instruction of 'main' .Set a breakpoint at the first instruction of the fact routine. Continue tracing through the program execution by using single stepping and/or breakpoints
      1. What is the register $sp used for?
      2. Draw the values on the stack when the first instruction of the fact procedure is about to be executed for the fourth time.
    6. Convert your fact program to use a simple loop, rather than recursion, to compute the factorial. Show that it works. You might examine the loop.s and while.s files for examples of looping constructs. Both of these programs require the user to enter return after the output has been generated in the console - I wanted the console to stay active so I put in an extra syscall. Place the modified fact.s file in your lab folder.
    7. Submit the zip of your local folder via email

Note: In QtSPIM, if the first line in `User Text Segment` is not the first line in the program set the PC regster with the address of the first line of the program