GNU/Linux xterm-256color zsh 147 views

.global _start

.section .bss
input:  .skip 20       // Buffer para número en texto (máx. 19 dígitos + '\n')

.section .rodata
msg_si: .asciz "ES PALINDROMO\n"
msg_no: .asciz "NO ES PALINDROMO\n"

.section .text
_start:
    // --- Leer número desde teclado ---
    mov x0, #0           // STDIN
    ldr x1, =input       // Dirección del buffer
    mov x2, #20          // Longitud máxima
    mov x8, #63          // syscall read
    svc 0                // Ejecutar syscall

    // x0 contiene bytes leídos
    mov x3, x0           // x3 = longitud con posible '\n'
    ldr x1, =input       // x1 = inicio del buffer

    // --- Eliminar '\n' si está presente ---
    sub x3, x3, #1
    ldrb w4, [x1, x3]
    cmp w4, #10
    bne skip_trim
    sub x3, x3, #1       // descontamos el '\n'
skip_trim:
    // x3 = última posición válida (índice final)
    mov x2, #0           // x2 = índice inicial

check_palindrome:
    cmp x2, x3
    bge es_palindromo    // Si se cruzan, es palíndromo

    ldrb w5, [x1, x2]    // w5 = input[inicio]
    ldrb w6, [x1, x3]    // w6 = input[fin]
    cmp w5, w6
    bne no_palindromo    // si son distintos, no es palíndromo

    add x2, x2, #1       // avanzar inicio
    sub x3, x3, #1       // retroceder fin
    b check_palindrome

// --- Palíndromo detectado ---
es_palindromo:
    ldr x1, =msg_si
    mov x2, #16          // longitud del mensaje
    b imprimir

// --- No es palíndromo ---
no_palindromo:
    ldr x1, =msg_no
    mov x2, #20

// --- syscall write(x0=1, x1=mensaje, x2=longitud) ---
imprimir:
    mov x0, #1
    mov x8, #64
    svc 0

    // Salir limpiamente
    mov x0, #0
    mov x8, #93
    svc 0