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{
while (ikey)
j--; if (ia[i++] = a[j];
while (ii++; if (ia[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:
https://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{
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{
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;
}
Deliverables:
the code should be properly commented