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

### Recently Asked Questions

- Please refer to the attachment to answer this question. This question was created from chap3 midtap homework . Additional comments: "How do i find the answer?"

- Is there a way to determine if two atoms will form ions or a covalent bond when they react?

- Please refer to the attachment to answer this question. This question was created from Chapter 2 exercises for foundations review 2.