Programming Laboratory I: Searching a String for a Character


Absolutely no copying others' work

Due Dates

The Objectives
Design and implement a simple assembly program, which is with about 40 lines. The purpose of this laboratory is to get you ready for assembly programming.



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/ .

    Select an Assignment and Enter the Password to Display the Code.

          Lab 1       Lab 2       Lab 3       Lab 4       Lab 5       Lab 6       Lab 7

      Password:                
    Make sure that Also, submit your password for displaying the code with the hard copy of the first assignment. For how to construct the web interface, refer to An Exercise.

  2. Turn in a CD labeled with your name and lab1.asm .


The Problem (Searching a String for a Character)
Write a program that checks whether a character is in a string. No error checking is required, i.e., assume the input is always correct. The following list shows some execution examples:

Examples of Laboratory 1 Execution
 
C:\250\lab\1\Debug> Project
 
The character c:  b 
 
The string s:   
 
The character c is NOT in the string s. 
 

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

The character c:  b

The string s:  abc

The character c is in the string s.

 
C:\250\lab\1\Debug> Project
 
The character c:  b 
 
The string s:  xyz 
 
The character c is NOT in the string s.
 
 
C:\250\lab\1\Debug> Project
 
The character c:  y 
 
The string s:  This is only a test. 
 
The character c is in the string s.
 
 
C:\250\lab\1\Debug> Project
 
The character c:  .
 
The string s:  This is only a test.
 
The character c 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 Crlf Writes an end of line sequence to standard output. 115
3 call ReadChar Reads a single character from the keyboard and returns the character in the AL register. 120
4 call WriteChar Writes a single character to standard output. Place the character in AL before calling the procedure. 123
5 call WriteString Writes a null-terminated string to standard output. When calling it, place the string's offset in EDX register. 124
6 cmp Performs an implied subtraction of a source operand from a destination operand. 156
7 .code Marks the beginning of the code segment. 55
8 .data Marks the beginning of the data segment. 55
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 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
13 je Jump if equal 158 – 162
14 jmp Causes an unconditional transfer to a target location inside the code segment. 104
15 jne Jump if not equal 158 – 162
16 mov Move 81 – 82
17 OFFSET Returns the offset of a data label. 94
18 PROC Identifies the beginning of a procedure. 59




A Suggested Procedure
You may also refer to the Getting Started page from the textbook author. The symbol * means the step is for the first-time use only.
  1. *Download and install Visual C++ 2005 Express Edition and Visual C++ 2008 Express Edition.

  2. *Download and install Microsoft MASM 8.0.

  3. *Download the textbook's Example Programs.

  4. Start the Visual C++ 2008 Express: Select from the Start menu of Windows:
       Start  All Programs  Visual C++ 2008 Express Edition
          Microsoft Visual C++ 2008 Express Edition
  1. *Set Tab size to 5: Select the following options from the Visual C++ 2008 Express:
       Tools  Options  Text Editor  All Languages  Tabs
    and set the Tab size and Indent size to 5.

  1. Build and execute an assembly-language program.

    1. Copy the folder c:\Irvine\Examples\ch03\Project_Sample to another folder such as c:\250\lab\1.

    2. Select the options of Visual C++ 2008 Express:
         File  Open  Project/Solution...
    3. Open a project such as c:\250\lab\1\Project.

    4. In the Solution Explorer window, click the mouse next to the item named Project to expand it. Double-click the file named main.asm to open it in the Editor window. Use this program, a template, as a starting point to write your own programs.

    5. Select Build Solution from the Build menu of Visual C++ 2008 Express. In the Output window at the bottom of the Visual C++ Express, you should see the messages indicating the build progress such as:
         1>------ Rebuild All started: Project: Project, Configuration: Debug Win32 ------
         1>Deleting intermediate and output files for project 'Project', configuration 'Debug|Win32'
         1>Assembling...
         1> Assembling: .\main.asm
         1>Linking...
         1>Embedding manifest...
         1>Build log was saved at "file://c:\250\lab\1\Debug\BuildLog.htm"
         1>Project - 0 error(s), 0 warning(s)
         ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
    6. Select Start Without Debugging from the Debug menu. The console window should appear such as:


      The “Press any key to continue...” message is automatically generated by Visual C++ Express. Press any key to close the console window.



Evaluation
The following features will be considered when grading: