Você está na página 1de 4

Processor Interfacing Laboratory

Experiment No. 4 Title: String operations. Aim: Write ALP to perform string manipulation to calculate string length and reverse a string.
The strings to be accepted from the user is to be stored in code segment Module_1 and write FAR PROCEDURES in code segment Module_2 for following operations on the string: i. Concatenation of two strings ii. Compare two strings iii. Number of occurrences of a sub-string in the given string iv. Find number of words, characters, number of lines and number of capital letters from the given text in the data segment Objective: Implementation of string instructions and study types of procedure.

Theory:
1. Assembler Directives PUBLIC: uses to know the linker that the variable/procedure can be accessed from other modules. EXTRN: used to know that the procedures and variables are not in this module. The EXTRN statement also gives the linker some needed information about procedures and variables. 2. DOS functions: used functions are 01H, 02H, 09H, 0AH, 4CH of INT 21H 3. New instructions used with explanation: LODS/LODSB/LODSW: This instruction copies a byte from string location pointed by SI. If direction Flag =0, SI will automatically incremented to point the next element of the string. MOVSB: instruction copies a byte from the location pointed by SI register to location pointed by DI register. It automatically increment SI pointer to next source location and automatically increment DI pointer to next destination. STOSB: this instruction copies byte from AL to memory location in the extra segment pointed by DI. If direction Flag is = 0 DI will automatically incremented by 1 for a byte string or by 2 for word string. CMPSB: this is used to compare a byte in one string with a byte in another string or to compare a double word in one string with a double word in another string. (E)SI is used to hold the offset of a byte or word in the source string and (E)DI is used to hold the offset of a byte or word or a double word in the other string. The comparison is done by subtracting the byte or word pointed to by (E)DI from the byte or word double word pointed to by (E)SI. The AF,CF,OF,PF,SF, and ZF flags are affected by the comparison, but neither operand is affected.

Input: Different strings Output: Display of Length of entered string Displaying entered string in reverse order Page - 1 -

Experiment No. 4

Processor Interfacing Laboratory


Concatenated two strings Compared result of two strings that is both are equal or Not Count of occurrences of sub-string Detailed display of number of CHRACTERS, WORDS, LINES within entered string

Main Algorithm:
i) Start ii) Enter the two string as per the input iii) Enter the choice and accordingly concatenate the two strings/Compare the two strings/check if 2nd string is substring of 1st string as per the user choice and check out courses of number of words, capital letters, number of lines. iv) Display the output. v) Stop

Macros:
1. Name : message 2. Purpose: to display the messages by replacing the whole code by simple macro declaration 3. I/P: 09 function with INT 21H

Procedure: 1
1. 2. 3. 4. Name : Proc_ Reverse _NEAR Purpose : to display the entered string in reverse order I/P : enter the string Algorithm for Procedures Enter the string and to calculate the length of string copy the content from fist location and display the length. Increment SI pointer upto end of string Store the length of the string in one counter register Display all characters starting from end by displaying each character decrement the counter by 1 until becomes 0

Procedure: 2
1. 2. 3. 4. Name : proc_ concatenate _FAR Purpose : to concatenate the entered two strings I/P : two entered strings Algorithm for Procedures For Concatenating operation set one pointer to end of 1st string Second pointer to start of 2nd string, Then go on appending the characters of the second string in to the array of first string till the length of second string is covered. Return to main menu

Procedure: 3
1. Name : proc_ compare_ FAR Experiment No. 4 Page - 2 -

Processor Interfacing Laboratory


2. Purpose: to perform comparison between two entered strings and display result of both are equal or Not 3. I/P : entered strings 4. Algorithm for Procedures For comparing operation set one pointer to the start of 1st string Second pointer to the start of 2nd string. Then first compare the length if length is not equal display message Strings are Not equal If length is equal then compare the string character wise, if equal then display equal strings, otherwise display unequal strings. Return to main menu

Procedure: 4
1. Name : proc_ Sub-string_ FAR 2. Purpose: to compare both strings and compare the entered string is sub string of main string or not. 3. I/P : main and sub string 4. Algorithm for Procedures For Substring operations ,enter two strings and initialized one counter = 0 check for the length of two strings if 2nd string length is larger, obviously it is not a substring. If 2nd string length is lower than the 1st string length then compare string character wise. If match found then display as 2nd string is substring of first, otherwise 2nd is not the substring of 1st string. If string having match of sub-string increment the count by one and scan the remaining string in same way to find out multiple occurrences of sub string upto end of the main string. Return to main menu

Procedure: 5
1. 2. 3. 4. Name : proc_ capital_line_word_character_FAR Purpose :to display the number of lines ,number of capital characters ,number of words I/P : entered string Algorithm for Procedures Enter the string and store the length of the string. Compare ASCII value of each character to checkout for capital letters within the range 65 to 91 simultaneously checkout 20H for blank space to calculate the number of words Display occurrence of capital letters /words/line/character etc.

Calculations (if any): not applicable Conclusion: Based on the understanding of the concepts used and studied in the assignment

Experiment No. 4

Page - 3 -

Processor Interfacing Laboratory


Platform Used: Windows XP SP3, Microsoft Macro Assembler. References: Douglas V Hall., Microprocessors and Interfacing
Program listing with comments and input, output. Mr. Tushar B Kute (Sandip Institute of Technology and Research Centre, Nashik)

Experiment No. 4

Page - 4 -

Você também pode gostar