// ****************************************************************************
// * Nombre del archivo: practica.s
// * Descripción: Calcula los segundos en un dia
// * Autor: Roldan Castro Luis Alberto
// * Fecha: 10-04-2025
// * Plataforma: Raspberry Pi OS (64 bits)
// * Asciinema: https://asciinema.org/a/nAuMU6LM5cbfFqvH4bErCQtfr
// ****************************************************************************
// ****************************************************************************
// Version en JavaScript
//
// Definir las constantes
//const segundosPorMinuto = 60;
//const minutosPorHora = 60;
//const horasPorDia = 24;
//
// Calcular los segundos en un día
//const segundosEnUnDia = segundosPorMinuto * minutosPorHora * horasPorDia;
//
// Imprimir el resultado
//console.log("Segundos en un día:", segundosEnUnDia);
// ****************************************************************************
.section .data
msg: .ascii "Segundos en un dia: "
len_msg = . - msg
nl: .ascii "\n"
len_nl = . - nl
.section .bss
buf: .skip 16 // buffer para print_int
.section .text
.global _start
_start:
// Calcular 24 * 60 * 60 = 86400
mov x0, #24
mov x1, #60
mul x2, x0, x1 // x2 = 1440
mov x0, x2
mov x1, #60
mul x3, x0, x1 // x3 = 86400
// Mostrar mensaje
ldr x0, =msg
mov x1, #len_msg
bl print_msg
// Mostrar resultado
mov x0, x3
bl print_int
// Nueva línea
ldr x0, =nl
mov x1, #len_nl
bl print_msg // ← corregido aquí
// Salida
mov x8, #93
mov x0, #0
svc #0
// --------------------------------------------------
print_msg: // x0 = ptr, x1 = len
mov x2, x1
mov x1, x0
mov x0, #1 // stdout
mov x8, #64 // syscall write
svc #0
ret
// --------------------------------------------------
print_int: // x0 = número a imprimir
sub sp, sp, #16
mov x1, x0
mov x2, sp
cmp x1, #0
b.ne int_convert
mov w3, #'0'
strb w3, [x2]
mov x2, #1
b int_print
int_convert:
mov x3, #10
mov x4, x2
int_loop:
udiv x5, x1, x3
msub x6, x5, x3, x1
add x6, x6, #'0'
sub x4, x4, #1
strb w6, [x4]
mov x1, x5
cmp x1, #0
b.ne int_loop
sub x2, x2, x4
mov x1, x4
int_print:
mov x0, #1
mov x8, #64
svc #0
add sp, sp, #16
ret