View the step-by-step solution to:

Implement the C code in the table in MIPS assembly:

Implement the C code in the table in MIPS assembly:

#define N 30
int a[N] = {
24, 14, 7, 8, 15, 11,
29, 18, 19, 3, 22, 28,
16, 17, 25, 23, 13, 30,
4, 9, 20, 10, 27, 5,
12, 1, 26, 6, 21, 2
};
void quicksort(int a[],int l,int h)
{
if (l>=h)
return;
int j, i, key;
i=l;
j=h;
key=a[i];
while(i<j)
{
while (i<j && a[j]>key)
j--; if (i<j)
a[i++] = a[j];
while (i<j && a[i]<key)
i++; if (i<j)
a[j--] = a[i];
}
a[i] = key;
if (l < i-1)
quicksort(a, l, i-1);




if (i+1 < h)
quicksort(a, i+1, h);
}
int main() {
quicksort(a, 0, N-1);
return 0; }

-Reference:
http://en.wikipedia.org/wiki/Quicksort

Task 2 Implement the C code in the table in MIPS assembly:
int StrLen( const char* str )
{
const char* ptr = str;
for ( ; 1; ++ptr )
{
if ( *ptr == '' )
return ptr - str;
} }
#define MAX_S 101 /** max text length 100 **/
#define MAX_P 21 /** max pattern length 20 **/
char s[MAX_S]="HERE IS A SIMPLE EXAMPLE", p[MAX_P]="EXAMPLE"; /** s is text; p is pattern **/
int nextv[MAX_P]; /** p's nextv array **/
void init_nextv()
{
int i = 0, j = -1;
int p_len; /** pattern length **/
p_len = StrLen(p);
nextv[0] = -1;
while (i<p_len-1)
{
if (j == -1 || p[i] ==p[j])
{
++i;
++j;
if (p[i] != p[j])
nextv[i] = j;




else
nextv[i] = nextv[j];
} // End if
else
{
j = nextv[j];
}
} // End while
}
int kmp() {
int i=0,j=0,s_len,p_len;
s_len=StrLen(s);
p_len=StrLen(p);
while(i<s_len && j<p_len)
{
if(j==-1 || s[i]==p[j])
{
i++;
j++; }
else j=nextv[j];
}
if(j==p_len)return i-p_len;
else return -1;
}
int main() {
int index=0;
init_nextv();
index=kmp();
return 0;
}

-Reference:
http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm

Deliverables:
the code should be properly commented

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question