0% found this document useful (0 votes)
215 views5 pages

Assembly Program: Palindrome Check

The document describes an experiment to write an assembly language program that checks if a given string is a palindrome. It outlines the software and theory used, provides a 16-step algorithm to reverse the string and compare it to the original, and includes the assembly code with comments. The code initializes data segments, prints strings, loads registers, compares letters in the original and reversed strings, and prints the result.

Uploaded by

Gopal Sawant
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)
215 views5 pages

Assembly Program: Palindrome Check

The document describes an experiment to write an assembly language program that checks if a given string is a palindrome. It outlines the software and theory used, provides a 16-step algorithm to reverse the string and compare it to the original, and includes the assembly code with comments. The code initializes data segments, prints strings, loads registers, compares letters in the original and reversed strings, and prints the result.

Uploaded by

Gopal Sawant
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/ 5

Experiment 3

AIM: To write an assembly level program to check if a given string is a palindrome.

SOFTWARE: 1) TASM
2) TLINK
3)TD
4)DOSBOX

THEORY:
The 8086 processor allows us to perform various arithmetic operations on Strings and numbers.
Following is the implementation of the checking if a given string is a palindrome or not using
string instructions.

ALGORITHM:
Step 1: Initialize Data segment with the values of the string which is to be checked and also
with the messages that are to be printed.
Step 2: Initialize the print function which will be used to print the strings.
Step 3: Initialize memory locations in the extra segment which will be used to store the reversed
string.
Step 4: In the code section, Load DS register with base address of Data segment and also load
the ES register with the base address of the extra segment.
Step 5: Load the effective address of Block1 into the SI register and also the effective address
of the last location of Block2 into the DI register.
Step 6: Load CX register with a count equal to the length of the word.
Step 7: Clear the direction flag and load the first letter in Block1 into the AL register. Then set
the direction flag, and store the first letter which was present in the AL register
previously starting from the last location in Block2.
Step 8: Repeat step 7 until the count is 0.
Step 9: Print the original string.
Step 10: Print the reversed string on a new line.
Step 11: Now load the starting addresses of Block1 and Block2 into the SI and DI register
respectively.
Step 12: Load CX register with a count equal to the length of the word.

Step 13: Clear the direction flag.


Step 14: Repeatedly compare the letters in Block1 and Block2 until the zero flag is cleared.
Step 15: If the zero flag is not set at any point, jump to the Skip label and print that the string
is not a palindrome; else print that the string is a palindrome.
Step 16: End of the program
FLOWCHART:
CODE:

DATA SEGMENT
BLOCK1 DB 'MALAYALAM'
MSG1 DB "IT IS PALINDROME $"
MSG2 DB "IT IS NOT PALINDROME $"
MSG3 DB "WORD IS MALYALAM $"
MSG4 DB "REVERSE IS MALYALAM $"
PAL DB 00H
DATA ENDS

PRINT MACRO MSG


MOV AH,09H
LEA DX,MSG
INT 21H
INT 3H
ENDM

EXTRA SEGMENT
BLOCK2 DB 9 DUP(?)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA

START:
MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
LEA SI,BLOCK1
LEA DI,BLOCK2+8
MOV CX,00009H

BACK: CLD

LODSB
STD
STOSB
LOOP BACK

LEA SI,BLOCK1
LEA DI,BLOCK2
MOV CX,0009H
CLD
REPZ CMPSB
PRINT MSG3
PRINT MSG4
JNZ SKIP
PRINT MSG1
JMP a
SKIP:
PRINT MSG2
a:CODE ENDS
END START
RESULT:

CONCLUSION: Thus we have checked whether a given string is a palindrome in assembly


language program using TASM software.

You might also like