Author Topic: Palindrome  (Read 111 times)

Offline Shark44

  • New Member
  • Posts: 1
Palindrome
« on: April 25, 2019, 03:59:48 PM »
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: [Select]
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

Offline fredericopissarra

  • Jr. Member
  • *
  • Posts: 34
Re: Palindrome
« Reply #1 on: April 25, 2019, 08:53:06 PM »
Change:
Code: [Select]
cmp [eax], [ecx]To:
Code: [Select]
mov dl,[ecx]
cmp [eax],dl