Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start by making a copy of this Y 8 6 - 6 4 example darr from class. Copy / paste the contents of the file

Start by making a copy of this Y86-64 example darr from class. Copy/paste the contents of the file into this
simulator G to run/debug. Run/debug the program until you're comfortable with the general structure of the
program, including the main and sum procedures and how they affect registers and memory. In particular, try
making changes to the input array and observing how the output of sum is aggregated in the %rax register using
a loop (and how the loop keeps track of pointers, indices, etc). Please follow up during office hours or on piazza
with questions! Then...
(20) Add a Y86-64 swap procedure equivalent to the following C code. Copy the C code into your Y86-64
program as a comment. Assume that %rdi will hold xp and %rsi will hold yp :
void long ?**xp, long {:?**yp){
long x=?**xp;
long y=?**yp;
?**xp=y;
?**yp=x;
}
Comment each line of your Y86-64 code in terms of xp,yp,x, and y.
(30) Add a Y86-64 sort procedure equivalent to the following C code. Copy the C code into your Y86-64
program as a comment. Assume that %rdi will hold arr and %rsi will hold length; also assume that this
procedure will call your swap procedure above as appropriate:
void sort(long *arr, long length){
long *iPtr = arr; // pointer to arr[i]
for (long i=0;i length -1;++i){
long *minPtr = iPtr; // pointer to smallest value found so far in rest of arr
long ** jPtr = iPtr +1;?? pointer to arr[j]
for (long j=i+1;j length ; ++j){
// update minPtr if array j less than value at minPtr
if jptr **minPtr
}
minPtr = jPtr;
}
++jPtr; // increment array[j] pointer
// swap if a value was found smaller than that at iPtr
if (minPtr != iPtr){
}
swap(minPtr, iPtr);
}
++iPtr; // increment array [i] pointer
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

More Books

Students also viewed these Databases questions