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

  • 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.

Howdy, Stranger!

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

Categories

In this Discussion