Name: Date:
CSSE232 Practical 3 Worksheet
Read and perform the lab guide posted on the course website. Answer the questions in the practical guide. Numbers in square brackets (e.g. []) indicate the point value of each question. The annotations in parentheses refer to the list of "general practical requirements" from the practical page. The answers to these questions should be as concise as possible. Maintain the spacing provided by this template.
Sum (p2)
-
[4] (Need) What are the three uses of
x5
? Which lines of the program correspond to each of these three uses? Write a one-sentence description of what the instruction is doing. -
[4] (Need) Where are
main
,loop
,done
,N
andSum
located (i.e. what address)? Hint: Assemble and use Settings > Show Labels Window in the Execute view. -
[4] (Performance) How many instruction does your modified program execute when
N
is equal to 5? How many additional instructions (over the original) is this? Can this be improved? If so, how? -
[4] (Correctness) Will your modified program work if
N
is less than 0? You do not need to make any additional modifications yet, but answer the question and consider how you might address any problems.
Swap (p3)
-
[4] (Correctness) What is the value of max and maxindex at the end of the program? Are they what you expect?
-
[4] Comment out
slli x10, x7, 2
and re-assemble and run the program. What happens? Compare the address table between the program with and withoutslli
. Which is correct and why? -
[4] Examine the value of
x10
and its use inlw x10, 0(x10)
. What does “Load address not aligned to word boundary 0x10010001” mean? Why did commenting out the slli instruction invalidate the program? Explain in the context of thex10
,x10
’s value, and how the.data
memory segment is organized. -
[4] (Need/Correctness) If you repeatedly apply your modified program to the subarrays of
A
from 0 to \( N-i \) where \(i\) is the number of times you've applied your program, what is the final state ofA
? -
[4] (Iteration/Correctness) Like
p2.asm
this program doesn't work ifN
is equal to 0. It is brittle in other ways as well. For example, what happens if all of the elements are less than -1? What if they are all -2^{31}, the max negative value? Is there a more robust way to ensure the max value is identified?
Sort (p4)
-
[4] (Need) If
SwapMaxWithLast
needed to return two values — the two values swapped in its execution — for debugging purposes, what changes to p4-swap would need to be made to accomplish this? -
[4] If SwapMaxWithLast needs to call another procedure in its execution, what changes to p4-swap would need to be made to accomplish this?
-
[4] (Iteration) If
p4-loop
needs to be converted into a procedure — similar to what you did when refactoring p3 intop4-swap
, what changes top4-loop
would need to be made to accomplish this?
Fib (p5)
-
[8] (Need) Look at the registers being used and notice that
s
registers are being used to store bothn
andfib(n-1)
. An alternative is to use t-registers instead. What are the differences between usings
andt
registers to implement fib? Are there any performance differences between the two? Which would you choose and explain why. -
[4] With your chosen approach, how is your stack frame organized for each fib call? Create a table describing how your stack frame is organized (each table row illustrates a word on the stack, detail the SP offset, content on the stack, etc.).
-
[4] (Correctness) Once you've correctly implemented
fib
: If you callfib(5)
, does it behave as expected? How many times is fib recursively called?
-
[8] (Correctness) In fib, you should have two internal calls to fib. Assemble and set a breakpoint at the line right AFTER the first internal call to fib. Then, while calculating
fib(5)
, observe the state of the stack when the breakpoint is hit (i.e., when the first recursivejal ra, fib
returns).Take a screenshot of the stack in RARS (Execute tab → Data Segment panel → dropdown Menu → current sp), and use colored boxes to box out each stack frame.
-
[4] (Correctness) What happens if
fib
does not restore the return address before usingjalr x0, 0(ra)
?
GIT
- [0] What is the git commit ID for your final commit of your code. This is required to pass the assignment. Check Practical 1 for instructions on how to get the correct commit ID.