Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Palindrome program

hello I am new here

i have a program that has to see if the input from the user is a palindrome or not. a palindrome is anything (letters or numbers) that reads the same forward as it does backwards. an example is "madam, i'm adam."

i am able to display the message and get the user input but i am having trouble with the compare part (to determine if it's a palindrome or not). we are not allowed to use any library's in the MASM program.

can anyone help?

Comments

  • emu8086emu8086 Posts: 125Member
    It is assumed that you have the size of the string
    in "s_size" variable, if not just calculate it
    and put it there...

    Here's the code:

    [code]
    #make_COM# ; required only for emu8086.

    ORG 100h

    jmp start

    s DB 'aaabbbaaa'
    s_size DW 9

    start:

    LEA DI, s
    MOV SI, DI
    ADD SI, s_size
    DEC SI ; point to last char!

    MOV CX, s_size
    SHR CX, 1 ; divide by 2!

    next_char:
    MOV AL, [DI]
    MOV BL, [SI]
    CMP AL, BL
    JNE not_Palindrome
    INC DI
    DEC SI
    LOOP next_char


    is_Palindrome:
    ; print out "Palindrome!"
    JMP stop

    not_Palindrome:
    ; print out "Not Palindrome!"
    stop:
    RET
    [/code]
  • : It is assumed that you have the size of the string
    : in "s_size" variable, if not just calculate it
    : and put it there...
    :
    : Here's the code:
    :
    : [code]
    : #make_COM# ; required only for emu8086.
    :
    : ORG 100h
    :
    : jmp start
    :
    : s DB 'aaabbbaaa'
    : s_size DW 9
    :
    : start:
    :
    : LEA DI, s
    : MOV SI, DI
    : ADD SI, s_size
    : DEC SI ; point to last char!
    :
    : MOV CX, s_size
    : SHR CX, 1 ; divide by 2!
    :
    : next_char:
    : MOV AL, [DI]
    : MOV BL, [SI]
    : CMP AL, BL
    : JNE not_Palindrome
    : INC DI
    : DEC SI
    : LOOP next_char
    :
    :
    : is_Palindrome:
    : ; print out "Palindrome!"
    : JMP stop
    :
    : not_Palindrome:
    : ; print out "Not Palindrome!"
    : stop:
    : RET
    : [/code]
    :


    Thanks,
    that helped out

    arod289
Sign In or Register to comment.