NASM Forum > Programming with NASM

Palindrome

(1/1)

Shark44:
Hello, I want to verify if a word is palindrome but I can't compare 2 memories. Can someone tell me a way to fix this?

--- Code: ---SECTION .text
global  _start

_start: ; tell linker entry point.
    mov ecx, string
    add ecx, len
    sub ecx, 3
    mov eax, string
    mov ebx, len
    _ciclo:
    push eax
    push ecx 
    cmp [eax], [ecx]
    jnz _stampaNonPalindroma
    pop ecx
    pop eax
    inc eax
    dec ecx
    dec ebx
    cmp ebx,0h
    jnz _ciclo
    jmp _stampaPalindroma ;se uscirà "indenne" dal ciclo vuol dire che la parola è palindroma
_stampaPalindroma:
    mov ecx, string2
    mov edx, len2
    mov ebx, 1  ; file descriptor (stdout)
    mov eax, 4  ; system call number (sys_write)
    int 0x80
    jmp _esci

_stampaNonPalindroma:
    mov ecx, string3
    mov edx, len3
    mov ebx, 1
    mov eax, 4
    int 0x80
    jmp _esci

_esci:
    mov     eax, 1
    int     0x80

section .data
string: db "anna",10,13 ;10 line feed, 13 carriage return, 0 null.
len:    equ $-string
string2: db "Palindroma",10,13
len2:   equ $-string2
string3: db "Non Palindroma",10,13
len3:   equ $-string3
--- End code ---

fredericopissarra:
Change:

--- Code: ---cmp [eax], [ecx]
--- End code ---
To:

--- Code: ---mov dl,[ecx]
cmp [eax],dl
--- End code ---

Navigation

[0] Message Index

Go to full version