0% found this document useful (0 votes)
46 views

Mic 11

This microproject aims to count the occurrences of a character in a given string using an assembly language program. The program prompts the user for input, iterates through the string comparing each character to the target character, and increments a counter for each match. It then displays the total count of occurrences.

Uploaded by

patelprit6505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Mic 11

This microproject aims to count the occurrences of a character in a given string using an assembly language program. The program prompts the user for input, iterates through the string comparing each character to the target character, and increments a counter for each match. It then displays the total count of occurrences.

Uploaded by

patelprit6505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Mahavir Polytechnic, Nashik

(Year: 2023-2024)
Micro Project

Program: COMPUTER ENGINEERING

Semester: Fourth Semester

Course: MICROPROCESSOR

Course Code: 22415

Title of the Project: Assembly Language Program to find number of occurrences of


user character from the given string.

______________________________________________

Members of the Group

1. Prit Patel Roll No. 49

2. Dhruv Vasani Roll No. 42

3. Krish Patel Roll No. 45

Mahavir Polytechnic
1
Vision

We strive to educate students to become industry ready engineers having professional attitude and
groomed personality.

Mission

· To provide well defined system to ensure quality education by strengthening teaching learning
processes through innovative practices

· To provide a platform where students are exposed to the industry, up bridged with the industry
standards and requirements.

· To train students by teaching them leadership and teamwork skills.

· To groom students enriching their personality and social values

Computer Engineering Department

Vision
Computer Engineering Department strives to educate students to become Industry ready Engineers
having Professional attitude and groomed personality.

Mission
. To provides well defined system to ensure quality education by strengthening teaching learning
processes through innovative practices.

. To provides a platform where students are exposed to the industry, up bridged with the industry
standards and requirements.

. To train students by teaching them leadership and teamwork skills.

. To groom students enriching their personality and social values.

2
PART A

1.0 Brief Introduction


In this microprocessor course our micro project topic is to find the number of occurrences of
user character in the given string. In this project our group will develop a program on the problem
statement given. In this program on the output screen ‘Enter the string’ this message will be printed.
Then the system will find out the number of occurrences of letters of the string and then the number
of the occurrences will be printed on the output screen.

2.0 Aim/Benefits of the Micro – Project

In this Microproject we are going to accept occurrence of user character. This will help to find
occurrences of user character from the given string.
1.To get the knowledge about microprocessor and assembly language.
2.To Understand the concept of given problem statement.
3.To develop a program to find the number of occurrences of a letter in the given string.

3.0 Course Outcomes Addressed

1 Write assembly language program for the given problem

2 Use instructions for different addressing modes.

3 Develop an assembly language program using assembler.

4 Develop assembly language program using macro and modular programming approach.

4.0 Proposed Methodology

1. The project team will be formed first.


2. Discussing the topic with team members and respective guide
3. Gather information about microproject.
4. Prepare flowchart and algorithm.
5. Checklist instructions and assembly directives.
6. Implement microproject code.
7. After finalizing the topic, we will prepare a proposal and submit to respective teacher.
8. After finalization of proposal we will start implementing our assembly language program.
3
9. We will timely report to project guide for necessary guidelines and correction in the
implementation.
10. After implementing and finalizing project we will start making project report.
11. Project report is also shown to project guide till its finalization.
12. After completing the above steps, we will submit out project documents to project guide and
give viva.

Progress Report / Weekly Report


Week Duration Sign of the
Date Work / Activity Performed
No in Hrs. Faculty
1

5.0 Resources Required

Name Of
Sr. No Specifications Quantity Remarks
Resource/Material

1
SOFTWARE I5 11gen -
2
SOURCE OF INFORMATION Google, Chat GPT -

Sign of Course Teacher


4
MICROPROJECT REPORT
1.0 Rationale
This assembly language program serves as a fundamental tool for string manipulation and
character search tasks. Its importance lies in its efficiency and simplicity, making it invaluable for low-
level programming tasks, embedded systems development, and educational purposes in computer
science and engineering.
2.0 Aim/Benefits of the Micro – Project

For this assembly language application, literature evaluations would examine effective

character search algorithms and optimization strategies. They would draw attention to the value of

educational pedagogy in teaching low-level programming as well as the importance of assembly

language in embedded systems development.

3.0 Literature Review

For this assembly language application, literature evaluations would examine effective

character search algorithms and optimization strategies. They would draw attention to the value of

educational pedagogy in teaching low-level programming as well as the importance of assembly

language in embedded systems development.

4.0 Actual Methodology

The methodology of the provided assembly language code involves prompting the user to
input a string and a character to search for. It then iterates through the input string character by
character, comparing each character with the target character. As each match is found, a counter is
incremented to keep track of the number of occurrences. Finally, the program displays the total count
of occurrences of the target character in the input string. This methodology demonstrates

5
fundamental string manipulation and control flow techniques in assembly language programming.

5.0 Actual Resources Used

Name Of
Sr. No Specifications Quantity Remarks
Resource/Material

1
SOFTWARE I5 11gen 8gb Ram 1
2
SOURCE OF INFORMATION Google, Chat GPT 1

6.0 Outputs of the Micro-Projects


This assembly language program aims to count the occurrences of a specific character within a given string.
It initializes a string ‘input_string’ and a character ‘search_char’ to be searched for within the string. It then
iterates through each character in the string, comparing it with the ‘search_char’. Whenever a match is
found, it increments a counter ‘count_occurrences.’ Once the entire string has been searched, the program
displays the count of occurrences by outputting a predefined message "Number of occurrences: " followed
by the actual count to the standard output.
To achieve this, the program utilizes system calls to write messages and data to the standard output. After
displaying the result, it exits gracefully. This program can be assembled and linked for a specific platform to
generate an executable that counts the occurrences of the specified character in the given string.

7.0 Skill Developed / Learning outcome of this Micro-Project


 Assembly Language Proficiency: Writing programs in assembly language enhances understanding of
low-level computer architecture and operation. It requires grasping concepts such as registers,
memory access, conditional branching, and system calls.
 Problem-Solving: Designing a program to solve a specific task, such as counting occurrences of a
character in a string, requires breaking down the problem into smaller steps and implementing
efficient solutions within the constraints of assembly language.
 Algorithmic Thinking: Developing an algorithm to search for a character within a string and count its
occurrences involves logical thinking and algorithm design skills. Assembly language forces
programmers to think about how to efficiently implement algorithms using limited resources.
 Debugging and Troubleshooting: Debugging assembly language programs helps in understanding
program flow and identifying errors at a low level. This enhances debugging skills and fosters a deeper
understanding of program execution.

6
 Understanding System Calls: Utilizing system calls to interact with the operating system for
input/output operations demonstrates practical understanding of system-level programming
concepts.
 Project Management: Managing a micro-project involves planning, coding, testing, and refining the
solution. It provides experience in project management within a small scope, fostering organizational
skills and time management.
 Communication of Technical Concepts: Explaining the functionality and design choices of the micro-
project to others promotes the ability to articulate technical concepts clearly and concisely, an
essential skill in any technical field.

8.0 Applications of this Micro-Project


 Text Processing Utilities: Integration into tools for counting character occurrences in files or
streams.
 Data Analysis: Part of text mining or sentiment analysis pipelines for insights.
 String Manipulation Libraries: Contribution to library development or optimization.
 Security Tools: Building blocks for detecting suspicious patterns in strings.
 Bioinformatics: Adaptable for counting nucleotides or amino acids in biological sequences.
 Compiler Design: Useful for optimizing lexical analyzers or parsers.
 Embedded Systems: Efficient string manipulation for resource-limited environments.
 Education: Teaching tool for illustrating assembly language and system-level programming
concepts.

7
Character Occurrence Counter in Assembly Language

DATA SEGMENT

 The DATA SEGMENT section defines the data segment of the program.
 MSG1, MSG2, MSG3, MSG4, and MSG5 are strings used for displaying messages to the user.
 CHAR is a single-byte variable used to store the character entered by the user.
 COUNT is a single-byte variable used to store the count of occurrences of the specified
character in the string.
 P1, M1, L1, and P11 are various labels and variables used within the program.

DISPLAY OUTPUT:

8
DISPLAY is a macro used to display messages to the user. It takes the message as a parameter and
displays it using DOS interrupt INT 21H.

CODE SEGMENT:

 The CODE SEGMENT section defines the code segment of the program.
 ASSUME CS: CODE, DS:DATA directive is used to specify assumptions about the segment
registers.
 START is the entry point of the program. It initializes the data segment.

DISPLAY MESSAGE:

 The program prompts the user to enter a string and a character.


 MSG1 and MSG2 are used to prompt the user for input.

9
 INT 21H, AH=0AH is used to read a string from the user and store it at the specified address
(P1).
 The user-entered character is read using INT 21H, AH=1 and stored in the CHAR variable.

CHECKING CONDITIONS:

 The program then iterates through the entered string using a loop.
 Each character of the string is compared with the entered character (CHAR).
 If a match is found, the COUNT variable is incremented.
 After processing the entire string, the program checks if any occurrences were found.

10
 If occurrences are found, it displays a message with the count (MSG5), else it displays a
message indicating no occurrences were found (MSG4).
 Finally, the program exits.

Main Code:
DATA SEGMENT

MSG1 DB 10,13,'ENTER ANY STRING: - $'

MSG2 DB 10,13,'ENTER ANY CHARACTER: - $'

MSG3 DB 10,13,' $'

MSG4 DB 10,13,'NO CHARACTER FOUND IN THE GIVEN STRING $'

MSG5 DB 10,13,' CHARACTER(S) FOUND IN THE GIVEN STRING $'

CHAR DB?

COUNT DB 0

P1 LABEL BYTE

M1 DB 0FFH

L1 DB?

P11 DB 0FFH DUP ('$')

DATA ENDS

DISPLAY MACRO MSG

MOV AH,9

LEA DX, MSG

INT 21H

ENDM

CODE SEGMENT

ASSUME CS: CODE, DS:DATA


11
START:

MOV AX, DATA

MOV DS, AX

DISPLAY MSG1

LEA DX, P1

MOV AH,0AH

INT 21H

DISPLAY MSG2

MOV AH,1

INT 21H

MOV CHAR, AL

DISPLAY MSG3

LEA SI, P11

MOV CL, L1

MOV CH,0

CHECK:

MOV AL, [SI]

CMP AL, '$'; Check for end of string

JE END_CHECK

CMP AL, CHAR

JNE NOT_FOUND

12
INC COUNT

NOT_FOUND:

INC SI

LOOP CHECK

END_CHECK:

CMP COUNT,0

JNE CHAR_FOUND

DISPLAY MSG4

JMP EXIT

CHAR_FOUND:

DISPLAY MSG5

MOV DL, COUNT

ADD DL,30H

MOV AH,2

INT 21H

EXIT:

MOV AH,4CH

INT 21H

CODE ENDS

END START

13
**Introduction**

The given assembly code is designed to work on the Intel 8086 microprocessor architecture and is intended
to be executed in the MS-DOS environment. The program's primary objective is to count the occurrences of
a specific character within a user-provided string. It accomplishes this task by prompting the user to input a
string and a character, then searching the string for the specified character and displaying the count of
occurrences.

**Code Structure**

The code is divided into two main segments: the data segment and the code segment.

**Data Segment**

The data segment is responsible for defining and storing various variables, strings, and constants used
throughout the program. Here's a breakdown of the data segment:

1. `MSG1` to `MSG5`: These are predefined strings used for displaying prompts and messages to the user.
2. `CHAR`: A byte variable used to store the character entered by the user.
3. `COUNT`: A byte variable used to keep track of the number of occurrences of the specified character in
the user-provided string.
4. `P1`: A label representing the memory location where the user-entered string will be stored.
5. `M1`: A constant value of `0FFH` (255 in decimal), which is typically used as a sentinel value or a
placeholder.
6. `L1`: A byte variable used to store the length of the user-entered string.
7. `P11`: A buffer (an array of bytes) used to store the user-entered string, terminated by the '$' character.

**Code Segment**

14
The code segment contains the actual assembly instructions that perform the desired operations. Here's a
breakdown of the code segment:

1. The program starts by initializing the data segment register (`DS`) with the appropriate segment address.
2. The `DISPLAY` macro is defined, which encapsulates the code for displaying a string to the console using
the DOS interrupt `21H` with the function code `09H` (display string).
3. The program prompts the user to enter a string using the `MSG1` string and reads the user input into the
`P1` memory location using the DOS interrupt `21H` with the function code `0AH` (buffered input).
4. The program prompts the user to enter a character using the `MSG2` string and reads the character into
the `CHAR` variable using the DOS interrupt `21H` with the function code `01H` (character input).
5. The program initializes the `SI` register with the address of `P11` (the buffer containing the user-entered
string) and loads the length of the string into the `CL` register.
6. The `CHECK` loop begins, which iterates over each character in the user-entered string:
- The current character is loaded into the `AL` register.
- If the character is the '$' (end of string marker), the loop jumps to the `END_CHECK` label.
- If the character matches the user-entered character stored in `CHAR`, the `COUNT` variable is
incremented.
- The `SI` register is incremented to move to the next character in the string.
- The loop counter (`CL`) is decreased, and the loop continues if `CL` is not zero.
7. After the loop ends, the program checks the value of `COUNT`:
- If `COUNT` is zero, it means the specified character was not found in the string, so the program displays
the `MSG4` string ("NO CHARACTER FOUND IN THE GIVEN STRING").
- If `COUNT` is non-zero, it means the character was found in the string, so the program displays the
`MSG5` string ("CHARACTER(S) FOUND IN THE GIVEN STRING") and the count of occurrences by converting
the value of `COUNT` to its ASCII representation and displaying it.
8. Finally, the program exits by invoking the DOS interrupt `21H` with the function code `4CH` (terminate
program).

**Program Flow**

The program follows this general flow:

1. Prompt the user to enter a string.


15
2. Read the user-entered string into memory.
3. Prompt the user to enter a character.
4. Read the user-entered character into memory.
5. Initialize variables and registers for the string search.
6. Iterate over the characters in the string:
- Check if the current character matches the user-entered character.
- If a match is found, increase the count.
7. After the loop, check if the count is zero or non-zero.
8. Display the appropriate message based on whether the character was found or not.
9. If the character was found, display the count of occurrences.
10. Exit the program.

**Input/Output Operations**

The program utilizes various DOS interrupt services to perform input/output operations:

- `INT 21H` with function code `09H` is used to display strings to the console.
- `INT 21H` with function code `0AH` is used to read a string from the user input.
- `INT 21H` with function code `01H` is used to read a single character from the user input.
- `INT 21H` with function code `4CH` is used to terminate the program.

These interrupt services were part of the MS-DOS operating system and provided a standardized way for
assembly language programs to interact with the console and perform input/output operations.

**String Manipulation**

The program demonstrates several string manipulation techniques in assembly language:

- Storing strings in memory using special characters (e.g., '$') as terminators.


- Initializing memory locations with predefined string values.
- Using registers (`SI`) to traverse through the characters in a string.
- Comparing characters within a string with a specific character.
- Incrementing/decrementing registers to move to the next character in the string.

16
- Utilizing loop constructs (`LOOP` instruction) to iterate over the characters in the string.

These techniques are fundamental in assembly language programming for string manipulation and
processing.

**Character Comparison**

The program performs character comparison to determine if the current character in the string matches the
user-entered character. This is achieved using the `CMP` instruction, which compares the values in the `AL`
register (containing the current character from the string) and the `CHAR` variable (containing the user-
entered character). Based on the result of this comparison, the program either increments the `COUNT`
variable or moves to the next character in the string.

**Counting Occurrences**

The `COUNT` variable is used to keep track of the number of occurrences of the specified character in the
user-entered string. Whenever a match is found between the current character and the user-entered
character, the `COUNT` variable is incremented using the `INC` instruction. After the loop completes, the
final value of `COUNT` represents the total count of occurrences.

**Output Display**

The program uses predefined strings (`MSG4` and `MSG5`) to display messages to the user, indicating
whether the specified character was found in the string or not. If the character was found, the program
displays the count of occurrences by converting the value of `COUNT` to its ASCII representation using the
`ADD` instruction (`DL` register + `30H`) and displaying it using the DOS interrupt `21H` with the function
code `02H` (display character).

17

You might also like