Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I translate this from C++ to mips? int isSubstring(string s1, string s2) { int M = s1.length(); int N = s2.length(); /* A

How would I translate this from C++ to mips?

int isSubstring(string s1, string s2)

{

int M = s1.length();

int N = s2.length();

/* A loop to slide pat[] one by one */

for (int i = 0; i <= N - M; i++) {

int j;

/* For current index i, check for pattern match */

for (j = 0; j < M; j++)

if (s2[i + j] != s1[j])

break;

if (j == M)

return i;

}

return -1;

}

My attempt:

li $t2, 0 sub $s3, $s2, $s1 outer_loop: li $t3, 0 inner_loop: add $s2, $t2, $t3 bne $s2, $s1, exit # end of inner loop beq $t3, $s1, exit2 addi $t2, $t2, 1 ble $t2, $s3, outer_loop exit: mfc0 $a0, $14 # lw $a0, ($a0) # srl $a0, $a0, 6 # li $v0, 1 # code for break syscall

exit2: move $s4, $t2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago