// ****************************************************************************
// * Lenguajes de Interfaz en TECNM Campus ITT
// * Nombre del archivo: practica.s
// * Descripción: Programa que imprime los numeros en cuenta regresiva a partir de N
// * Autor: [America Fernanda Nevarez de la Cruz]
// * Fecha: [2025-04-08]
// * Plataforma: Raspberry Pi OS (64 bits)
// * Demostración: [https://asciinema.org/a/6F1lhjHc1ejUaJUSaokFpNESg]
// ****************************************************************************
// ****************************************************************************
// * Codigo equivalete en Ruby
// *puts "Ingrese un numero: "
// *gets.to_i.downto(0) { |n| puts n }
// ****************************************************************************
.section .bss
buffer: .skip 64
.section .data
msg_ingrese: .ascii "Ingrese un numero: "
len_ingrese = . - msg_ingrese
nl: .ascii "\n"
.section .text
.global _start
_start:
// Mostrar mensaje
ldr x0, =msg_ingrese
mov x1, #len_ingrese
bl print_msg
// Leer entrada
mov x0, #0
ldr x1, =buffer
mov x2, #64
mov x8, #63
svc #0
// Convertir a entero
ldr x1, =buffer
mov x2, #0
parse_loop:
ldrb w3, [x1], #1
cmp w3, #'0'
blt fin_parse
cmp w3, #'9'
bgt fin_parse
sub w3, w3, #'0'
mov x4, #10
mul x2, x2, x4
add x2, x2, x3
b parse_loop
fin_parse:
// x2 = número inicial
mov x20, x2
cuenta_abajo:
// Imprimir número actual
mov x0, x20
bl print_number
// Imprimir salto de línea
ldr x0, =nl
mov x1, #1
bl print_msg
// Decrementar
subs x20, x20, #1
bge cuenta_abajo
// Fin
mov x8, #93
mov x0, #0
svc #0
// --- Función: imprimir texto ---
print_msg:
mov x2, x1
mov x1, x0
mov x0, #1
mov x8, #64
svc #0
ret
// --- Función: imprimir número ---
print_number:
mov x1, x0
ldr x2, =buffer
add x2, x2, #63
mov w3, #0
convert_loop:
mov x4, #10
udiv x5, x1, x4
msub x6, x5, x4, x1
add x6, x6, #'0'
strb w6, [x2], #-1
mov x1, x5
add w3, w3, #1
cbnz x1, convert_loop
add x2, x2, #1
mov x1, x2
mov w2, w3
mov x0, #1
mov x8, #64
svc #0
ret