Solved

Palindrome?

Posted on 2003-11-19
7
2,371 Views
Last Modified: 2012-06-27
Dear All,

Can anyone teach me how to write a 68000 assembly language programme which will check whether a string is palindrome or not?

Thanks!
0
Comment
Question by:cplau
7 Comments
 
LVL 1

Accepted Solution

by:
vbs03 earned 200 total points
ID: 9785884
Hi just go through the following code written for x86

        .MODEL SMALL
        .STACK 64
        .DATA
STRPAR LABEL   BYTE
MAXLEN  DB      20
ACTLEN  DB      ?
STR1     DB      20 DUP ('-')

REVSTR  DB      20 DUP ('-')
PROMPT  DB      ' ENTER THE STRING : ','$'

PAMSG   DB      0DH,0AH,' THE ENTERED STRING IS A PALINDROME ! ','$'
NPAMSG  DB      0DH,0AH,' THE ENTERED STRING IS NOT A PALINDROME ! ','$'

        .CODE
BEGIN   PROC    NEAR
        MOV     AX,@DATA
        MOV     DS,AX
        MOV     ES,AX
        CALL    CLRSCR
        CALL    SETCUR
        CALL    ACCSTR
        CALL    REV
        MOV     AH,02H
        MOV     BH,00H
        MOV     DX,1240H
        CALL    CHECKP
        MOV     AX,4C00H
        INT     21H
BEGIN   ENDP

CLRSCR  PROC    NEAR
        MOV     AX,0600H
        MOV     BH,0CH
        MOV     CX,0000H
        MOV     DX,184FH
        INT     10H
        RET
CLRSCR  ENDP

SETCUR  PROC    NEAR
        MOV     AH,02H
        MOV     BH,00H
        MOV     DX,0000H
        INT     10H
        MOV     AH,01H
        MOV     CH,10
        MOV     CL,14
        INT     10H
        RET
SETCUR  ENDP

ACCSTR  PROC    NEAR
        MOV     AH,09H
        LEA     DX,PROMPT
        INT     21H
        MOV     AH,0AH
        LEA     DX,STRPAR
        INT     21H
        MOV     BH,00H
        MOV     BL,ACTLEN
        MOV     AL,'$'
        MOV     [STR1+BX],AL
        RET
ACCSTR  ENDP

REV     PROC    NEAR
        MOV     BH,00
        MOV     BL,ACTLEN
        LEA     DI,STR1
        LEA     SI,[DI+BX]
        LEA     DI,REVSTR
        MOV     CH,00
        MOV     CL,ACTLEN
        DEC     SI
ACTREV :
        MOV     AL,[SI]
        MOV     [DI],AL
        INC     DI
        DEC     SI
        LOOP    ACTREV
        MOV     AL,'$'
        MOV     [DI],AL
        MOV     AH,09H
        LEA     DX,REVSTR
        INT     21H
        MOV     AH,02H
        MOV     BH,00H
        MOV     DX,0640H
        INT     10H

        RET
REV     ENDP

CHECKP  PROC    NEAR
        CLD
        MOV     CH,00
        MOV     CL,ACTLEN
        DEC     CX
        LEA     SI,STR1
        LEA     DI,REVSTR
        REPE    CMPSB
;        CMP     CX,0000H
        JE      PMSG
        MOV     AH,09H
        LEA     DX,NPAMSG
        INT     21H
        JMP     CEND
PMSG :
        MOV     AH,09H
        LEA     DX,PAMSG
        INT     21H
CEND :
        RET
CHECKP  ENDP
        END     BEGIN

If u need detailed instructions please post ur query. Hope this helps.
Regards
VBS



0
 
LVL 3

Expert Comment

by:kenspencer
ID: 9827527
Hi,
vbs03 -- Just a comment.   Why bother creating a second string?  After you establish SI/DI pointing at the beginning/end of the input string then you could perform a compare and jump out of the loop on a 'not equal' condition.

Ken
0
 

Expert Comment

by:Daramarak
ID: 9908964
Hm... sounds like homework to me (I might ofcourse be wrong).
0
 

Expert Comment

by:Saintslayer
ID: 13190790
can anyone tell me how to write a LC-3 assembly language to check whether a string is palindrome or not?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now