GNU/Linux xterm-256color zsh 138 views

.section .data
msj_esc:     .asciz "Triángulo escaleno\n"
msj_iso:     .asciz "Triángulo isósceles\n"
msj_equ:     .asciz "Triángulo equilátero\n"
buffer_a:    .space 8
buffer_b:    .space 8
buffer_c:    .space 8

.section .text
.global _start

_start:
    // Leer lado a
    mov x0, #0
    ldr x1, =buffer_a
    mov x2, #8
    mov x8, #63
    svc 0

    // Convertir a
    ldr x1, =buffer_a
    bl ascii_to_int
    mov w20, w0     // w20 = a

    // Leer lado b
    mov x0, #0
    ldr x1, =buffer_b
    mov x2, #8
    mov x8, #63
    svc 0

    // Convertir b
    ldr x1, =buffer_b
    bl ascii_to_int
    mov w21, w0     // w21 = b

    // Leer lado c
    mov x0, #0
    ldr x1, =buffer_c
    mov x2, #8
    mov x8, #63
    svc 0

    // Convertir c
    ldr x1, =buffer_c
    bl ascii_to_int
    mov w22, w0     // w22 = c

    // ----------------------
    // Comparaciones
    // ----------------------

    // Si a == b y b == c → equilátero
    cmp w20, w21
    bne check_isosceles
    cmp w21, w22
    bne check_isosceles

    // Equilátero
    mov x0, #1
    ldr x1, =msj_equ
    mov x2, #21
    mov x8, #64
    svc 0
    b end

check_isosceles:
    // Si a == b || b == c || a == c → isósceles
    cmp w20, w21
    beq isosceles
    cmp w21, w22
    beq isosceles
    cmp w20, w22
    beq isosceles

    // Escaleno
    mov x0, #1
    ldr x1, =msj_esc
    mov x2, #20
    mov x8, #64
    svc 0
    b end

isosceles:
    mov x0, #1
    ldr x1, =msj_iso
    mov x2, #22
    mov x8, #64
    svc 0

end:
    // Salir
    mov x0, #0
    mov x8, #93
    svc 0

// -----------------------------------------------------------
// ascii_to_int: convierte buffer ASCII a entero positivo
// Entrada: x1 = buffer
// Salida: w0 = número
// -----------------------------------------------------------
ascii_to_int:
    mov w0, #0
    mov w2, #0
    mov w3, #10

parse_loop:
    add x4, x1, x2
    ldrb w5, [x4]
    cmp w5, #'0'
    blt end_parse
    cmp w5, #'9'
    bgt end_parse
    sub w5, w5, #'0'
    mul w0, w0, w3
    add w0, w0, w5
    add w2, w2, #1
    b parse_loop

end_parse:
    ret