汇编实现回文判断


不多说,直接上代码

DATA    SEGMENT  
Prompt  DB  'Please enter a string:$'  
YesStr  DB  13, 10, 'This string is palindrome$'  
NoStr   DB  13, 10, 'This string is not palindrome$'  
Input   DB  128, ?, 128 DUP(0)  
DATA    ENDS  
STACK   SEGMENT  
    DB  128 DUP(?)  
STACK   ENDS  
CODE    SEGMENT  
    ASSUME  CS:CODE, DS:DATA, SS:STACK  
MAIN:     
    MOV AX, DATA  
    MOV DS, AX  
    MOV DX, offset Prompt  
    MOV AH, 09H  
    INT 21H  
    ;  
    MOV DX, OFFSET Input  
    MOV AH, 0AH  
    INT 21H  
    ;  
    MOV DI, OFFSET Input  
    MOV SI, OFFSET Input  
      

    XOR CX, CX  
    MOV CL, [DI+1]  
    ADD DI, 2  
    ADD SI, 2  
    DEC CX  
    ADD DI, CX  
    ;force DI point to the last word of Input  
AGAIN:  
    CMP SI, DI  
    JA  TESSKIP  
    MOV AH, byte ptr [SI]  
    MOV AL, byte ptr [DI]  
    CMP AH, AL  
    JNE NOSKIP  
    INC SI  
    DEC DI  
    JMP AGAIN  
TESSKIP:  
    MOV DX, OFFSET YesStr  
    MOV AH, 09H  
    INT     21H  
    JMP ENDSKPI  
    ;  
  
NOSKIP:  
    MOV DX, OFFSET NoStr  
    MOV AH, 09H  
    INT     21H  
    ;  
ENDSKPI:  
    MOV AH, 4CH  
    INT     21H  
      
CODE    ENDS  
    END MAIN  

文章作者: jerrycheese
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 jerrycheese !
  目录