Slide 4.17: CALL instruction
Slide 5.2: Defining data
Home

Programming Laboratory II: Searching a String for a Pattern


Absolutely no copying others' work

Due Dates

The Objectives
This lab is an extension of the Lab 1. Design and implement an assembly program which searches a string for a pattern. Students learn how to use control structures from this lab, which is with about 60 lines.



Submission Methods
Turn in hard-copy assembly code and apply either one of the following two methods:
  1. Post the assembly code at http://people.cs.und.edu/~userid/250/ .
  2. Turn in a CD labeled with your name and lab2.asm .


The Problem (Searching a String for a Pattern)
Write a program that searches a non-empty string for a non-empty pattern. No error checking is required, i.e., assume the input is always correct. The following list shows some execution examples:

Examples of Laboratory 2 Execution

C:\250\lab\2\Debug> Project

The pattern p: b
 
The string s: abc

The pattern p is in the string s.
 

C:\250\lab\2\Debug> Project
 
The pattern p: x
 
The string s: abc
 
The pattern p is NOT in the string s.
 
 
C:\250\lab\2\Debug> Project
 
The pattern p: abc
 
The string s: xyzabc123
 
The pattern p is in the string s.
 
 
C:\250\lab\2\Debug> Project
 
The pattern p: on
 
The string s: This is only a test.
 
The pattern p is in the string s.
 
  
C:\250\lab\2\Debug> Project
 
The pattern p: onto
 
The string s: This is only a test.
 
The pattern p is NOT in the string s.
 
 
C:\250\lab\2\Debug> Project
 
The pattern p: a test
 
The string s: This is only a test.
 
The pattern p is in the string s.
      

where the italic text with a yellow background is entered by users.



Possible Instructions Used
The following operators, directives, and commands may be used in this lab:

No. Operators/
Directives/
Commands
Description Textbook
Page
Numbers
1 BYTE Directive of defining byte 66 – 67
2 call ReadString Reads a string from the keyboard, stopping when the user presses the Enter key. 122
3 call WriteString Writes a null-terminated string to standard output. When calling it, place the string's offset in EDX register. 124
4 cmp Performs an implied subtraction of a source operand from a destination operand. 156
5 .code Marks the beginning of the code segment. 55
6 .data Marks the beginning of the data segment. 55
7 DUP Generates a repeated storage allocation, using a constant expression as a counter. 67
8 DWORD Directive of defining doubleword 68
9 END Marks the last line of the program to be assembled. 59
10 ENDP Marks the end of a procedure. 59
11 exit Calls a predefined MS-Windows function that halts the program. 59
12 inc Increment 87
13 INCLUDE Irvine32.inc Copies necessary definitions and sets up information from a text file name Irvine32.inc, located in the assembler's INCLUDE directory. 59
14 jmp Causes an unconditional transfer to a target location inside the code segment. 104
15 jne Jump if not equal 158 – 162
16 loop Loop. ECX is automatically used as a counter and is decremented each time the loop repeats. 105 – 106
17 mov Move 81 – 82
18 OFFSET Returns the offset of a data label. 94
19 PROC Identifies the beginning of a procedure. 59
20 SIZEOF Size of a data item 97



Evaluation
The following features will be considered when grading: