PEP-8 - 检查Word是否是回文

时间:2015-11-18 18:59:56

标签: assembly palindrome pep8-assembly

我已经为回文程序整理了输入,但我对如何检查输入的单词是否是回文没有任何想法。

; Program to read name and output greeting 
            BR  main 
        name:   .BLOCK 32           ;space for up to 32 characters 
    msg1:   .ASCII "The word is: \x00" 
    msg2:   .ASCII "Enter a word: \x00" 
    main:   LDX 0,i             ; load index register with 0
            STRO    msg2,d      ;output word prompt 
    chin:   CHARI   name,x          ;read a character 
            LDA name,x      ;and load accumulator 
            ADDX    1,I     ;add 1 to index register 
            CPA 0x0A00,i    ;compares with line feed 
            BREQ    out     ;if line feed go to out 
            BR  chin        ;go to chin to read next char 
    out:    LDA '\x00',I        ;load acc with end of string 
            STA name,x      ;store end of string in name block
            STRO    msg1,d      ;output word message 
            STRO    name,d      ;output stored name
            STOP 
    .END

有人可以帮我解决这个问题吗?谢谢。

1 个答案:

答案 0 :(得分:2)

这是一些简单的C-ish伪代码,可以帮助您入门:

Left = Start;
Right = Start + Length - 1;

while (Left <= Right)  
{
  if Word[Left] != Word[Right]
    not a palindrome, exit
  Left++;
  Right--;
}
palindrome