String matching: Difference between revisions

Content added Content deleted
Line 3,028: Line 3,028:
=={{header|MIPS Assembly}}==
=={{header|MIPS Assembly}}==
The function below returns the zero-based index where the string pointed to by <code>$a1</code> occurs in <code>$a0</code>.
The function below returns the zero-based index where the string pointed to by <code>$a1</code> occurs in <code>$a0</code>.
* If it returns strlen(<code>$a0</code>), then <code>$a1</code> was not found.
* If it returns <tt>strlen($a0)</tt>, then <tt>$a1</tt> was not found.
* If it returns 0, then <code>$a0</code> begins with <code>$a1</code>.
* If it returns 0, then <tt>$a0</tt> begins with <tt>$a1</tt>.
* If it returns strlen(<code>$a0</code>)-strlen(<code>$a1</code>), then <code>$a0</code> ends with <code>$a1</code>.
* If it returns <tt>strlen($a0)-strlen($a1)</tt>, then <tt>$a0</tt> ends with <tt>$a1</tt>.
* Otherwise, <code>$a0</code> contains <code>$a1</code> starting at the specified location.
* Otherwise, <tt>$a0</tt> contains <tt>$a1</tt> starting at the specified location.
* Multiple occurrences can be detected by adding the output to <tt>$a0</tt> and repeating the process; this is left as an exercise to the reader.
<lang mips>InString:
<lang mips>InString:
;input: $a0 = ptr to string 1
;input: $a0 = ptr to string 1