Homework 4 - Searching the input

As you are aware, we have lab assignments due every week. We also will have several homework assignments this semester, and this is one of them. While the labs are directed, the homework assignments present larger problems that you should break down into smaller problems. You should spend some time thinking about and planning your homework solutions before coding them.

Program Description

In this assignment, you are to create an assembly language program that compiles with nasm on SNOWBALL, and runs. We have seen how to perform input and output in assembly. Refer to the recent lab on I/O. Try this on multiple inputs, using the pipe and redirection as shown in previous labs. Verify that this gives correct responses.

Searching is a common function. Computers can quickly go through a lot of information, and highlight the places where a string is found. Your task in this homework is to make a program to look through the input, and report where the search string is found. It should report each instance, and output the offsets within the input.

For example, suppose that the string to find is the letter 'o', and the input is the text "hello world". Your program should report that it is found at position 4 and position 7.

If the search string is not found, your program should output nothing.

To make this simple, assume that the search string is the first thing in the input stream, with a new-line character after it. For example, here is what the input to find the 'o' characters in "hello world." looks like


    o
    hello world.

Assumptions

Make sure that your program works for other inputs, that is, use different files to test your program. Consider difficult cases, such as finding "aab" in "aaab". And if you are looking for "aa" in "aaaa", it should find it 3 times.

Since you will need to reserve some memory to store the string-to-find, limit it to 1000 characters. Do not hard-code this value within the program; instead, set up a label for it with "equ". This way, if you later decide to make the maximum number of characters more or less, you can easily change it in one place. If there is no new-line character in the first 1000 inputs characters, have your program print an error message and quit.

At a minimum, show that your solution works for the following files.



Notes: