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.

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

Sign up to view the entire interaction

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