0% found this document useful (0 votes)
32 views3 pages

Exp 4

The document provides instructions for writing an assembly language program to count the number of times an alphabet repeats in a string. It outlines the objectives, necessary instructions like CMP and JNZ, and an algorithm for the program. The algorithm initializes data, loads the string and length, clears a register, uses a loop to compare characters and increment a counter, and displays the result. It also provides an example program in assembly language format with comments.

Uploaded by

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

Exp 4

The document provides instructions for writing an assembly language program to count the number of times an alphabet repeats in a string. It outlines the objectives, necessary instructions like CMP and JNZ, and an algorithm for the program. The algorithm initializes data, loads the string and length, clears a register, uses a loop to compare characters and increment a counter, and displays the result. It also provides an example program in assembly language format with comments.

Uploaded by

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

Count an Alphabet Repeat in a String

Aim: - Write an assembly language program in 8086 to count no. of times an


alphabet is repeated in a string.

Objectives: -
Students will be able
i) To draw the flow chart and develop the logic how an alphabet is repeated in
a string.
ii) To understand assembler directives and write program in assembly language
iii) To understand the function of compiler and assembler
iv) To understand the difference between language and machine language.

Theory:-

The following instructions are useful for developing assembly level language
program:

i) CMP:

ii) JNZ:

iii) Loop:

Algorithm:-
1. Initialize the data segment
2. Initialize a string and length of string (String db ‘employee$’ and len db $-string)
3. Clear Al register
4. Move offset value of string in SI
5. Move length of the string as a counter in CL register
6. Take alphabet in BH
7. Compare BH with desired alphabet (eg. cmp bh,’e’)
8. Increment Al register if comparison answer is zero else jump to step 9
9. Increment memory to access next alphabet of string
10.Decrement the counter, if not zero jump to step 6
11.Display result in memory with variable “ans”

1
Program:-

1) Count alphabet for a string


2)
.model small ; declaration of model for single DS, SS, CS, ES
.data ; Initialization of data segment
String db ‘employee$’ ; Declaration of string
Ans dd ? ; variable for storage of answer
len db $-string ; string length
.code ; initialization of code segment
start: ; start of code segment
mov ax,@data ; Base address of data segment
mov ds,ax ; the data moved in ax above is moved to ds
mov al,00h ; clear al register
mov SI, offset string ; Define offset string in SI
mov CL, len ; load Len in CL
back: mov bh, [SI] ; move content of memory location pointed by SI to bh
cmp bh,’e’ ; compare content of bh with e
jnz here ; jump if not zero to the label mentioned
inc AL ; AL = AL+1
here: inc SI ; increment SI
loop back ; back to Loop
lea bx,ans
mov [bx],al
mov ah,4ch ; load 4ch to ah
int 21h ; Terminate program
.exit ; returns to DOS
end start ; end of program

Result & Discussion:- write about the hex values of string and desired alphabet

String:- mention your string


Result:-
Before execution:
AL = CL =
BH = SI =
After execution:
AL = CL =
BH = SI =

2
Output:-
AL =
Memory address where AL is stored = xxxxh =

Conclusion:
Write about LEA, SI, CMP, JNZ
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

Outco PLO PLO PLO Performa Attenda Total E&TC DEPARTMENT-


me 1 2 3 nce nce Score TCET

Date of Performance:
Weight 20 20 20 20 20 100
_________

Date of Correction:
___________

Roll No: _________


Score
Marks: ______ / 100

Signature of Faculty:

You might also like