Question: I am trying to convert C code to a working translation of Y 8 6 - 6 4 assembly . Pay close to attention what

I am trying to convert C code to a working translation of Y86-64assembly. Pay close to attention what is and is not allowed in Y86(no $ symbol). Here is the code in C:
//Function to perform linear search
//Returns the index of the element if found, -1otherwise
//Counts the number of comparisons made during the search
int linearSearch(int arr[],int size, int value, int *comparisonCount){
*comparisonCount =0; //Initialize comparison count
for (int i =0; i size; i++){
(*comparisonCount)++; //Increment comparison count
if (arr[i]==value)
return i; //Element found
}
return -1; //Element not found
}
This Implements linear search to find an integer in an array, tracking the number of comparisons made. This routine will help explore control flow and basic data handling in assembly.
For the linear search assembly program, it should be designed to handle parameters pushed onto the stack in reverse order. Begin with the array (arr[])at the top of the stack, followed by size, then value, and finally, comparisonCount at the bottom.
The assembly routine will then retrieve these parameters from the stack, perform the linear search operation to find the value within arr[],and keep track of the number of comparisons made during the search in comparisonCount. The search should iterate through each element of arr[],comparing it to value.
If value is found, the index at which value is found should be stored in \%rax for return, and comparisonCount should reflect the total comparisons made. If value is not found, \%rax should be set to -1,indicating failure to locate value, with comparisonCount still updated to reflect the number of comparisons made.
I am trying to convert C code to a working

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!