Snyder 17 April 2000

Programming Assignment No. 2

Write an assembly language program to solve the following problem. Given the inputs

$a0 = address of a "null-terminated" ASCII string, known as the text,

$a1 = address of a "null-terminated" ASCII string, known as the pattern,

return in $v0 the number of non-overlapping occurrences of the pattern in the text, and in $v1 the offset from the beginning of the text of the first occurrence of the pattern (or 0 if the pattern is not in the text). The pattern should match "case-insensitively," e.g. "HI", "Hi", "hI" and "hi", match each other. Also, the pattern might include one or more question marks "?", which means "match any single character". So, "H?", "h?", "?I" and "?i" match the previously listed strings (among others), as does "??".

The following might make this clearer.

Pattern

Text

$v0

$v1

Comments

Hi

Hike

1

0

The one pattern match is at the start

Hi

Shark

0

0

There are no matches

H?

Shark

1

1

Question mark matches the "a"

???

hhhhh

1

0

After first match, none can follow without an overlap

?

Count

5

0

The wild card matches each symbol, giving count

The programming goals are turn in a clean, well-documented program that is reasonably efficient. You will need a doubly nested loop in all likelihood, so make it plain to the reader the scope of the loops. You are required to write the program as a procedure (call it "match") called from a Main program, but you are not required to use any subsidiary procedures unless you think they can simplify the logic.

See the "Hello World" program for the syscall that prints out an ASCII string. The program will be submitted by e-turnin.