[Assembly] Stringa palindroma

Stato
Discussione chiusa ad ulteriori risposte.

imported_BlackLight

Utente Silver
16 Agosto 2007
211
8
1
98
Dopo uno spunto venuto dal mio forum, ho deciso di scrivere in Assembly una piccola applicazione che verifica se una stringa è palindroma. Sintassi AT&T, compilare con gcc.

Codice:
.data
str:            .space  128
msg:            .string "Inserire una stringa: "
mlen            =               .-msg

ok:             .string "La stringa e palindroma\n"
oklen   =               .-ok
ko:             .string "La stringa non e palindroma\n"
kolen   =               .-ko

.global main
.text
main:
        movl            $4,%eax
        movl            $1,%ebx
        movl            $msg,%ecx
        movl            $mlen,%edx
        int             $0x80

        movl            $3,%eax
        movl            $0,%ebx
        movl            $str,%ecx
        movl            $128,%edx
        int             $0x80

        movl            $str,%eax
        movl            $-1,%ecx
        cmpl            $0,%eax
        je              end_strlen

strlen:
        incl            %eax
        incl            %ecx
        cmpl            $0,(%eax)
        jne             strlen

end_strlen:
        movl            $str,%edx
        addl            %ecx,%edx
        movl            $0,(%edx)

        movl            $str,%edx
        movl            %edx,%eax
        movl            %edx,%ebx
        addl            %ecx,%ebx
        decl            %eax

loop:
        incl            %eax
        decl            %ebx
        movl            %eax,%esi
        movl            %ebx,%edi
        subl            %edx,%esi
        subl            %edx,%edi
        cmpl            %esi,%edi
        je              true

        incl            %esi
        cmpl            %esi,%edi
        je              true

        xorl            %esi,%esi
        xorl            %edi,%edi
        movl            (%eax),%esi
        movl            (%ebx),%edi
        andl            $0x000000ff,%esi
        andl            $0x000000ff,%edi
        cmpl            %esi,%edi
        jne             false
        jmp             loop

false:
        movl            $4,%eax
        movl            $1,%ebx
        movl            $ko,%ecx
        movl            $kolen,%edx
        int             $0x80
        jmp             end

true:
        movl            $4,%eax
        movl            $1,%ebx
        movl            $ok,%ecx
        movl            $oklen,%edx
        int             $0x80

end:
        movl            $1,%eax
        movl            $0,%ebx
        int             $0x80
 
[ot]
simogeta ha detto:
io mi chiedo: capisco il c++ ma non capisco l'assembly...xk? uffi!!


scusate se ho rovinato il topic

non capisco il senso di questo messaggio [/ot]

tornando in topic ottimo lavoro blacklight
 
[ot]
simogeta ha detto:
io mi chiedo: capisco il c++ ma non capisco l'assembly...xk? uffi!!


scusate se ho rovinato il topic [usare [ ot] no?]
Per l'asm serve logica, conoscienza architettura di un computer e 2 pa**e grosse come grattacieli, per il C++ basta mastercard
[/ot]
 
Stato
Discussione chiusa ad ulteriori risposte.