View the step-by-step solution to:

# CSE/EEE 230: Computer Organization and Assembly Programming Project 4 Date assigned: November 20th, 2012 Due date:30 pm, December 5th, 2012 (at the...

Implement the C codes in the table in MIPS assembly.

1.
#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;
}

2.
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;}

CSE/EEE 230: Computer Organization and Assembly Programming Project 4 Date assigned: November 20 th , 2012 Due date: 4.30 pm, December 5 th , 2012 (at the start of the lecture) Task 1 [50 points] 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 [50 points] Implement the C code in the table in MIPS assembly. int StrLen( const char * str ) { const char * ptr = str; for ( ; 1; ++ptr ) { if ( *ptr == '\0' ) 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;
Show entire document

### 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