You are on page 1of 11

Micro Processors Laboratory Manual

CYCLE: V

...STRING OPERATIONS...

Experiment 5.a

1. AIM:
Program to read and displaying the string of characters.

2. EQUIPMENT:
Pentium PC, TASM.

3. ALGORITHM:
1. Declare the prompting messages for read and write the string in
the data segment.
2. Declare the memory location for storing the string and moving a
cursor to the next line in the data segment.
3. Initialization of data segment.
4. Prompting a message to input the string before reading a string.
5. Input the string.
6. Moving cursor on to the next line.
7. Prompting a message to display the string before output a string.
8. Displaying the string.
9. Retain in DOS mode.
10. Terminate the program.

4. ASSEMBLY LANGUAGE PROGRAM:


Write the assembly language program on Editor.
.MODEL SMALL

; Size of the program.

.DATA

; Data part of the segment.

msg1

DB 'Enter the string ........: $'

msg2

DB 'Your entered string is ...: $'

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


string

label byte

; Location to store input string, its maximum

maxl

DB 20h

; length, actual length of the string, and

actl

DB ?

; duplicating all locations with '$'.

strfld

DB 20h dup('$')

nline

DB 10,13,'$'

.CODE
mov ax,@data

; Code part of the segment.


; Initialization of data segment.

mov ds,ax

lea dx,msg1

; A routine for prompting the message before

mov ah,09h

; reading a string.

int 21h

lea dx,string

; A routine for reading the string from the

mov ah,0ah

; keyboard.

int 21h

lea dx,nline

; Moving cursor on to next line.

mov ah,09h
int 21h

lea dx,msg2

; A routine for prompting message before

mov ah,09h

; displaying a string.

int 21h

lea dx,strfld

; A routine for displaying the string on DOS

mov ah,09h

; window.

int 21h

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


mov ah,4ch

; Retain in DOS mode.

int 21h

END

; End of the segments.

5. EXECUTING:
1. Edit, Assemble the program and check, if there no errors then Link
the program.
Assemble

: tasm rdsp.asm

Link

: tlink rdsp.obj

2. Run the program.


Debug

: rdsp

3. Enter and observe the strings in the DOS window.

6.OBSERVATION:
INPUT:
Enter the string ........: VIGNAN UNIVERSITY

OUTPUT:
Your entered string is ...: VIGNAN UNIVERSITY

...oOo...

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


CYCLE: V

...STRING OPERATIONS...

Experiment 5.b

1. AIM:
Program to read and reversing the string of characters.

2. EQUIPMENT:
Pentium PC, TASM.

3. ALGORITHM:
1. Declare the prompting messages for read and write the string in
the data segment.
2. Declare the memory location for storing the string and moving
a cursor to the next line in the data segment.
3. Initialization of data segment.
4. Prompting a message to input the string.
5. Input the string.
6. Initialize source and destination offset addresses of strings.
7. Initialize the actual length of the string in cl.
8. Pointing to the last character of the source string.
9. Reverse the string.
10. Moving cursor on to the next line.
11. Prompting a message to display the reversed string before
output a string.
12. Displaying the reversed string.
13. Retain in DOS mode.
14. Terminate the program.

5. ASSEMBLY LANGUAGE PROGRAM:


Write the assembly language program on Editor.

.MODEL SMALL

K.Vijaya Kumar, Asso.Prof.

; Size of the program.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


.DATA

; Data part of the segment.

msg1

DB 'Enter the string to be reversed ...: $'

msg2

DB 'Your reversed string is ...........: $'

string

label byte

; Location to store input string, its maximum

maxl

DB 20h

; length, actual length of the string, and

actl

DB ?

; duplicating all locations with '$'.

strfld1 DB 20h dup('$')


strfld2 DB 20h dup('$')

nline

DB 10,13,'$'

.CODE
mov ax,@data

; Code part of the segment.


; Initialization of data segment.

mov ds,ax

lea dx,msg1

; A routine for prompting message.

mov ah,09h
int 21h

lea dx,string

; A routine to reading the string.

mov ah,0ah
int 21h

lea si,strfld1

; Initialization of source and destination

lea di,strfld2

; string offset addresses.

mov cl,actl

; Actual length of the string in cl.

mov ch,00

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


add si,cx

; Pointing the last character of the source


; string.

bak:dec si

; Reversing the string.

mov al,[si]
mov [di],al
inc di
loop bak

lea dx,nline

; A routine for moving cursor on to next line.

mov ah,09h
int 21h

lea dx,msg2

; A routine for prompting message.

mov ah,09h
int 21h

lea dx,strfld2

; A routine for displaying the reversed string.

mov ah,09h
int 21h

mov ah,4ch
int 21h

; A routine for return to DOS mode.

END

; End of the segments.

5. EXECUTING:
1. Edit, Assemble the program and check, if there no errors then Link
the program.
Assemble

: tasm rdrv.asm

Link

: tlink rdrv.obj

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


2. Input the data in the specified memory or registers.
3. Run the program.
Debug

rdrv

4. Enter and observe the strings in the DOS window.

6. OBSERVATION:
INPUT:
Enter the string to be reversed ...: VIGNAN UNIVERSITY

OUTPUT:
Your reversed string is ...........: YTISREVINU NANGIV

...oOo...

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


CYCLE: V

...STRING OPERATIONS...

Experiment 5.c

1. AIM:
Program to find whether the given string is palindrome or not.

2. EQUIPMENT:
Pentium PC, TASM.

3. ALGORITHM:
1. Declare the prompting messages for read and write the string in
the data segment.
2. Declare the memory location for storing the string and moving
a cursor to the next line in the data segment.
3. Initialization of data segment.
4. Prompting a message to input the string.
5. Input the string.
6. Initialize source and destination offset addresses of strings.
7. Initialize the actual length of the string in cl.
8. Pointing to the last character of the source string.
9. Reverse the string.
10. Moving cursor on to the next line.
11. Compare the strings for equality.
12. If strings are equal then go to next step, otherwise got to step15.
13. Prompting a message to display the string is Palindrome.
14. Go to step 16.
15. Prompting a message to display the string is not Palindrome.
16. Retain in DOS mode.
17. Terminate the program.

4. ASSEMBLY LANGUAGE PROGRAM:


Write the assembly language program on Editor.

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual


.MODEL SMALL

; Size of the program.

.DATA

; Data part of the segement.

msg1

DB 'Enter the string ..........: $'

msg2

DB 'The reversed string is ....: $'

msg3

DB 'The string is palindrome $'

msg4

DB 'The string is not palindrome $'

string

label byte

; Location to store input string, maximum

maxl

DB 30h

; length, actual length of the string, and

actl

DB ?

; duplicating all locations with '$'.

strfld1 DB 30h dup('$')


strfld2 DB 30h dup('$')
nline

DB 10,13,'$'

.CODE

; New line routine.


; Code part of the segment.

mov ax,@data

; Initialization of data segment.

mov ds,ax
mov es,ax
lea dx,msg1

; A Prompting message before read.

mov ah,09h
int 21h

lea dx,string

; Reading the string.

mov ah,0ah
int 21h

lea si,strfld1
lea di,strfld2
mov cl,actl
mov ch,00
add si,cx

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

Micro Processors Laboratory Manual

bak:dec si

; Reversing the string.

mov al,[si]
mov [di],al
inc di
loop bak

lea dx,nline

; Moving cursor on to next line.

mov ah,09h
int 21h

lea dx,msg2

; A Prompting message before display.

mov ah,09h
int 21h

lea dx,strfld2

; Displaying the string.

mov ah,09h
int 21h

lea dx,nline

; Moving cursor on to next line.

mov ah,09h
int 21h

lea si,strfld1
lea di,strfld2
mov cl,actl
mov ch,00
repe cmpsb

; Comparing the string.

je down1
lea dx,msg4
jmp down2

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

10

Micro Processors Laboratory Manual


down1:lea dx,msg3

down2:mov ah,09h
int 21h

mov ah,4ch

; Retain in DOS mode.

int 21h

END

; End of the segments.

5. EXECUTING:
1. Edit, Assemble the program and check, if there no errors then Link
the program.
Assemble

: tasm palndrm.asm

Link

: tlink palndrm.obj

2. Input the data in the specified memory or registers.


3. Run the program.
Execute

palndrm

4. Enter and observe the strings in the DOS window.


6. OBSERVATION:
INPUT:
Enter the string ..........: VIGNAN

OUTPUT:
The reversed string is ....: NANGIV
The string is not palindrome

...oOo...

K.Vijaya Kumar, Asso.Prof.

School of Electronics, Vignan University, Guntur

11

You might also like