String matching: Difference between revisions

m
Line 3,028:
=={{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>.
* If it returns strlen(<codett>strlen($a0)</codett>), then <codett>$a1</codett> was not found.
* If it returns 0, then <codett>$a0</codett> begins with <codett>$a1</codett>.
* If it returns <tt>strlen(<code>$a0</code>)-strlen(<code>$a1)</codett>), then <codett>$a0</codett> ends with <codett>$a1</codett>.
* Otherwise, <codett>$a0</codett> contains <codett>$a1</codett> 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:
;input: $a0 = ptr to string 1
1,489

edits