String is palindrome or not. PDF

Title String is palindrome or not.
Author Prashant Saini
Course Microprocessor
Institution University of Mumbai
Pages 4
File Size 236.8 KB
File Type PDF
Total Downloads 121
Total Views 173

Summary

Syntax-CMP Destination, source
This instruction compares the contents of source with destination, shows equal
condition using zero flag
If source < destination, CF = 0,SF = 0,ZF = 0
If source > destination, CF = 1,SF = 1,ZF = 0
...


Description

Experiment- 5 Theory: CMP Syntax-CMP Destination, source

Aim: Write ALP to identify the string is palindrome or not.

This instruction compares the contents of source with destination, shows equal condition using zero flag If source < destination, CF = 0,SF = 0,ZF = 0 If source > destination, CF = 1,SF = 1,ZF = 0 JMP Program execution transfer instructions in 8086 microprocessor. Program execution transfer instructions are similar to branching instructions and refer to the act of switching execution to a different instruction sequence as a result of executing a branch instruction. Algorithm 1) Start 2) Initialize the memory areas and two pointers and a counter. 3) Print message “Enter the string “. 4) Accept the string, store it in reserved areas. 5) Pointer 1 pointing to area 1: while pointer 2 pointing to area 2. 6) Set the pointer 1 to first character of string and pointer 2 points to the last character of same string. 7) Compare both the characters. 8) If both characters are equal check counter If zero Print message “The string is palindrome” Else Increment pointer 1 by 1 and decrement pointer 2 by one and go to step 7 Else

Print message “The string is not palindrome”

9) Stop. Conclusion: Thus program to check valid palindrome is implemented by creating two copies of same Srting and comparing characters of both in reverse direction.

Program DATA SEGMENT MSG DB "ENTER STRING:$" MSG1 DB 0AH, "STRING IS PALINDROME$" MSG2 DB 0AH, "STRING IS NOT PALINDROME$" DATA ENDS DATA SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX,DATA MOV DS, AX MOV DX, OFFSET MSG MOV AH, 09H INT 21H MOV CL, 00H MOV DI, 2000H MOV SI, 1000H UP: MOV AH, 01H INT 21H MOV [SI], AL MOV [DI],AL INC SI INC DI INC CL CMP AL, 0DH JNZ UP MOV SI, 1000H SUB DI, 02H DEC CL UP1: MOV BL, [SI] CMP BL ,[DI] JNZ NOTPAL INC SI DEC DI DEC CL JZ DOWN JMP UP1

NOTPAL: MOV DX, OFFSET MSG2 MOV AH, 09H INT 21H JMP EX DOWN: MOV DX,OFFSET MSG1 MOV AH, 09H INT 21H EX: MOV AH,4CH INT 21H CODE ENDS END START Output: Before Execution: Enter the String: Nayan After Execution: The string is Palindrome...


Similar Free PDFs