Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (.txt or .pdf only). Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is not shown.
• (10) Allocate a hardcoded input array similar to that used by asum.ys (linked on course examples page) with at least 10 entries.
• (20) Implement a swap procedure equivalent to the following C code:
void swap(long *xp, long *yp) {
long t0 = *xp;
long t1 = *yp;
*xp = t1;
*yp = t0;
}
• (20) Implement a sort procedure that takes a pointer to an array and length of the array as arguments and sorts the input array using Selection Sort. Your sort procedure should call your swap procedure (using a call instruction) to perform the swaps and it should sort the array in place – there’s no need to allocate additional memory for an output array.
• (10) Implement a main procedure to call your sort procedure (using a call instruction), passing the input array and array length as arguments.
I recommend using the “Y86-64 simulator” (linked on the course Links page) as a programming environment. Use the Y86-64 examples from class and the textbook as a guide.
Hint: Y86-64 doesn’t have leaq or mult (or shifts, for that matter), so calculating a pointer from a base address and index is kinda a pain… Instead, consider using pointer arithmetic like we did back in assignment 4!
Hint: Y86-64 doesn’t have cmpq or testq, either; subq will do the trick, but be careful with the side effects!
Name your source file 5-1.ys.
Include your answer in your solutions document (a picture of a drawing is sufficient). Label
your inputs!
encounter many cases (e.g., lines 2 and 10) in which we want to add a constant value to a
register. This requires first using an irmovq instruction to set a register to the constant, and
then an addq instruction to add this value to the destination register. Using Figure 4.18 as a
guide, draw a diagram expressing how the existing Y86-64 architecture could implement a new
iaddq instruction to accomplish this functionality.