GNU/Linux xterm-256color zsh 141 views

.section .data
mensaje_si:    .asciz "Es divisible entre 2 y 5\n"
mensaje_no:    .asciz "NO es divisible entre 2 y 5\n"

.section .text
.global _start

_start:
    // -------------------------------
    // Cargar número a verificar
    // -------------------------------
    mov x0, #20            // Cambia este valor por cualquier otro

    // -------------------------------
    // Verificar divisibilidad entre 2
    // -------------------------------
    mov x1, #2
    udiv x2, x0, x1        // x2 = x0 / 2
    msub x3, x2, x1, x0    // x3 = x0 - (x2 * 2) = x0 % 2
    cmp x3, #0
    bne no_divisible       // si no es divisible entre 2, salta

    // -------------------------------
    // Verificar divisibilidad entre 5
    // -------------------------------
    mov x1, #5
    udiv x2, x0, x1        // x2 = x0 / 5
    msub x3, x2, x1, x0    // x3 = x0 - (x2 * 5) = x0 % 5
    cmp x3, #0
    bne no_divisible       // si no es divisible entre 5, salta

    // -------------------------------
    // Es divisible entre 2 y 5
    // -------------------------------
    ldr x1, =mensaje_si
    b imprimir

no_divisible:
    ldr x1, =mensaje_no

imprimir:
    // syscall write(stdout, mensaje, longitud)
    mov x0, #1             // file descriptor stdout
    mov x2, #27            // longitud del mensaje más largo
    mov x8, #64            // syscall número para write
    svc 0

    // syscall exit(0)
    mov x0, #0
    mov x8, #93            // syscall número para exit
    svc 0