// ****************************************************************************
// * Nombre del archivo: practica.s
// * Descripción: Encontrar la suma de 35 numeros enteros
// * Autor: Roldan CastrO Luis Alberto
// * Fecha: 07-04-2025
// * Plataforma: Raspberry Pi OS (64 bits)
// * Asciinema: https://asciinema.org/a/SWiri2J3rDX8pplQQksmZsIGa
// ****************************************************************************
// ****************************************************************************
//Version en RUST
//
//fn main() {
// let numeros = vec![
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
// 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
// 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
// 31, 32, 33, 34, 35
// ];
//
// let suma: i32 = numeros.iter().sum();
// println!("La suma es: {}", suma);
//}
// ****************************************************************************
.section .data
newline: .asciz "\n"
.section .bss
buffer: .skip 20
.section .text
.global _start
_start:
mov x0, #1 // Contador desde 1
mov x1, #0 // Acumulador de la suma
loop:
cmp x0, #36
b.ge imprimir
add x1, x1, x0 // x1 += x0
add x0, x0, #1
b loop
imprimir:
mov x0, x1 // Valor de la suma
bl print_number
// Salto de línea
ldr x0, =newline
mov x1, #1
bl print
// Salir
mov x8, #93
mov x0, #0
svc #0
// ----------------------------------------
// Imprimir número (entero sin signo) en x0
// ----------------------------------------
print_number:
ldr x1, =buffer
add x1, x1, #19
mov x2, #0
.num_loop:
mov x3, #10
udiv x4, x0, x3
msub x5, x4, x3, x0
add x5, x5, #'0'
sub x1, x1, #1
strb w5, [x1]
mov x0, x4
add x2, x2, #1
cmp x0, #0
b.ne .num_loop
mov x0, #1
mov x8, #64
mov x1, x1
mov x2, x2
svc #0
ret
// ----------------------------------------
// Imprimir cadena: x0 = ptr, x1 = len
// ----------------------------------------
print:
mov x2, x1
mov x1, x0
mov x0, #1
mov x8, #64
svc #0
ret