Assembly 协助回文汇编

Assembly 协助回文汇编,assembly,x86,nasm,Assembly,X86,Nasm,这就是我目前正在处理的问题 .DATA LF EQU 10 String_prompt DB "Enter a character string: ",0 Is_palindrome DB "The string is a palindrome.",0 Not_palindrome DB "The string is not a palindrome.",0 .UDATA user

这就是我目前正在处理的问题

.DATA

LF              EQU         10
String_prompt   DB          "Enter a character string: ",0
Is_palindrome   DB          "The string is a palindrome.",0
Not_palindrome  DB          "The string is not a palindrome.",0



.UDATA

user_input      resb        80  
strip_input     resb        80  

.CODE

.STARTUP
; Set up ES register
    mov         AX, DS
    mov         ES, AX

    try_again:    
        GetStr      user_input
        cmp         user_input, LF
        je          try_again
        mov         EDX, user_input
        call        string_convert




.EXIT

;********************************************
; string_convert: Eliminate blanks and 
;     punctuation. Convert to upper case
;
;********************************************        
string_convert:
        enter  0, 0
        xor     EBX, EBX
        mov     ECX, 80

        read:
            mov     AL, [EDX+EBX]
            cmp     AL, '0'
            jl      skip
            cmp     AL, '9'
            jg      check

            check:
                sub     AL, 20H
                cmp     AL, 'A'
                jl      skip
                cmp     AL, 'Z'
                jle     write
                cmp     AL, 5BH            :check for ASCII past 'Z'
                jge     skip

            skip:
                inc     EBX
                jmp     read

            write:
                push    AX
                push    ECX
                les     EDI, user_input
                mov     ECX, 80
                cld
                mov     AL, 0
                repne   scasb




        leave
        ret    
我已经知道了如何检查反转字符串的基本方法,使用堆栈来反转它,但是我还不知道如何将这些字符写入新字符串
strip\u input

有没有办法将未初始化的字符串与单个字符连接起来?我要做的是剥离
用户输入的所有标点符号和数字,同时将所有字符转换为大写。我想我的支票安排得很好,但我仍停留在写:
的过程中

还有没有更好的方法来读取用户输入的内容,而不是只接收80个字符?我觉得这将导致问题检查,如果它是回文,因为所有的空白空间。< /P> 所以我把它打印出来了,这就是我现在所在的位置,在第一次函数调用之后,我似乎遇到了一个错误

LF              EQU         10
String_prompt   DB          "Enter a character string: ",0
Is_palindrome   DB          "The string is a palindrome.",0
Not_palindrome  DB          "The string is not a palindrome.",0
index           DB          0



.UDATA

user_input      resb        80  
strip_input     resb        80  
final_input     resb        80

.CODE

.STARTUP
; Set up ES register
    mov         AX, DS
    mov         ES, AX

    try_again:    
        PutStr      String_prompt
        GetStr      user_input
        cmp         word[user_input], LF
        je          try_again

    call    string_convert
    call    string_reverse
    call    palindrome_check
    PutStr  user_input
    PutStr  strip_input
    PutStr  final_input
    cmp     EAX, 1
    jne     notP
    PutStr  Is_palindrome

    notP:
        PutStr  Not_palindrome


.EXIT

;********************************************
; string_convert: Eliminate blanks and 
;     punctuation. Convert to upper case
;
;********************************************        
string_convert:
        enter  0, 0
        xor     EBX, EBX
        mov     ECX, 80

        read:
            cmp     ECX, 0
            jz      endread   
            mov     AL, byte [user_input+EBX]
            cmp     AL, '9'
            jle     skip
            cmp     AL, 7BH
            jge     skip 

            check:
                inc     EBX
                or      AL, 20H
                cmp     AL, 'a'
                jl      skip
                cmp     AL, 'z'
                jle     write


            skip:
                inc     EBX
                loop    read

            write:
                ;PutCh   AL
                push    EBX
                mov     EBX, [index]
                mov     byte [strip_input+EBX], AL
                inc     EBX
                mov     [index], EBX
                pop     EBX
                loop    read

        endread:

        leave
        ret     
;*********************************************
; string_reverse: Recursive procedure to 
;     reverse string
;
;
;*********************************************
string_reverse:
        enter   0,0
        xor     EBX, EBX
        xor     EAX, EAX
        push    0

        checknull:
            mov     AL, byte [strip_input+EBX]
            PutCh   AL
            cmp     AL, 0
            je      reverse
            ret

        pushtostack:
            push    AX
            inc     EBX
            call    checknull

        reverse:
            xor     EBX, EBX
            pop     AX
            cmp     AL, 0
            je      end
            mov     byte [final_input+EBX],AL
            inc     EBX 
            jmp     reverse

        end:



        leave
        ret
;************************************************
;palindrome check: Check for palindrome
;
;************************************************
palindrome_check:
        enter   0,0
        push    ECX
        push    EDI
        push    ESI
        push    DS
        push    ES
        les     EDI, [strip_input]
        mov     EDX, 80
        lds     ESI, [final_input]
        cld
        repe    cmpsb
        je      same
        xor     EAX, EAX

        same:
            mov EAX, 1

        leave
        ret
C-prompt刚刚崩溃了

所以现在我把问题缩小了一些,不确定这是怎么发生的,但是EBX增加了2

string_reverse:
        enter   0,0
        xor     EBX, EBX
        xor     EAX, EAX
        xor     ECX, ECX
        push    00h

        checknull:
            mov     AL, byte [strip_input+EBX]
            PutLInt EBX
            inc     EBX
            PutCh   AL
            cmp     AL, 00h
            jne     pushtostack
            ret

        pushtostack:
            push    AX
            PutLInt EBX
            ;inc     EBX
            call    checknull

        reverse:
            pop     AX
            cmp     AL, 00h
            je      end
            mov     byte [final_input+ECX],AL
            inc     ECX 
            jmp     SHORT reverse

        end:



        leave
        ret
一旦它通过
strip\u输入完成循环,它就会崩溃,我想它涉及到
ret
,它通过
反向:

现在我唯一的问题是比较两个字符串
strip\u input
final\u input

我真的不知道该怎么做,有人能帮我吗?

为什么要反转字符串?获取您的输入,对其进行清理(删除无效字符),转换为大写或小写,然后获取第一个字节并与最后一个字节进行比较,增加正向索引并减少反向索引,然后再次进行比较,直到两个索引相等为止(字符串中间)。我们必须使用这种特定格式才能获得全额积分