Professional Documents
Culture Documents
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.
.DATA
msg1
msg2
label byte
maxl
DB 20h
actl
DB ?
strfld
DB 20h dup('$')
nline
DB 10,13,'$'
.CODE
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,09h
; reading a string.
int 21h
lea dx,string
mov ah,0ah
; keyboard.
int 21h
lea dx,nline
mov ah,09h
int 21h
lea dx,msg2
mov ah,09h
; displaying a string.
int 21h
lea dx,strfld
mov ah,09h
; window.
int 21h
int 21h
END
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
: rdsp
6.OBSERVATION:
INPUT:
Enter the string ........: VIGNAN UNIVERSITY
OUTPUT:
Your entered string is ...: VIGNAN UNIVERSITY
...oOo...
...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.
.MODEL SMALL
msg1
msg2
string
label byte
maxl
DB 20h
actl
DB ?
nline
DB 10,13,'$'
.CODE
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
lea dx,string
mov ah,0ah
int 21h
lea si,strfld1
lea di,strfld2
mov cl,actl
mov ch,00
bak:dec si
mov al,[si]
mov [di],al
inc di
loop bak
lea dx,nline
mov ah,09h
int 21h
lea dx,msg2
mov ah,09h
int 21h
lea dx,strfld2
mov ah,09h
int 21h
mov ah,4ch
int 21h
END
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
rdrv
6. OBSERVATION:
INPUT:
Enter the string to be reversed ...: VIGNAN UNIVERSITY
OUTPUT:
Your reversed string is ...........: YTISREVINU NANGIV
...oOo...
...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.
.DATA
msg1
msg2
msg3
msg4
string
label byte
maxl
DB 30h
actl
DB ?
DB 10,13,'$'
.CODE
mov ax,@data
mov ds,ax
mov es,ax
lea dx,msg1
mov ah,09h
int 21h
lea dx,string
mov ah,0ah
int 21h
lea si,strfld1
lea di,strfld2
mov cl,actl
mov ch,00
add si,cx
bak:dec si
mov al,[si]
mov [di],al
inc di
loop bak
lea dx,nline
mov ah,09h
int 21h
lea dx,msg2
mov ah,09h
int 21h
lea dx,strfld2
mov ah,09h
int 21h
lea dx,nline
mov ah,09h
int 21h
lea si,strfld1
lea di,strfld2
mov cl,actl
mov ch,00
repe cmpsb
je down1
lea dx,msg4
jmp down2
10
down2:mov ah,09h
int 21h
mov ah,4ch
int 21h
END
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
palndrm
OUTPUT:
The reversed string is ....: NANGIV
The string is not palindrome
...oOo...
11