String matching: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
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 |
* If it returns <tt>strlen($a0)</tt>, then <tt>$a1</tt> was not found. |
||
* If it returns 0, then < |
* If it returns 0, then <tt>$a0</tt> begins with <tt>$a1</tt>. |
||
* If it returns strlen( |
* If it returns <tt>strlen($a0)-strlen($a1)</tt>, then <tt>$a0</tt> ends with <tt>$a1</tt>. |
||
* Otherwise, < |
* 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 |