Skip to content

Instantly share code, notes, and snippets.

@enrmx
Created April 11, 2025 00:17
Show Gist options
  • Select an option

  • Save enrmx/6428b38bdfc6359211d04a1a9f431f7c to your computer and use it in GitHub Desktop.

Select an option

Save enrmx/6428b38bdfc6359211d04a1a9f431f7c to your computer and use it in GitHub Desktop.
/*
* ---------------------------------------------------------------------------->
* Lenguajes de Interfaz en TECNM Campus ITT
* Autor: Rodriguez Guerrero Garinel Enrique
* Fecha: 2025-04-09
* Descripción: Calcula el total de regalos del villancico "12 días de Navidad".
* ---------------------------------------------------------------------------->
*/
.global _start
.section .data
mensaje: .asciz "Total de regalos: "
nl: .asciz "\n"
.section .bss
.lcomm buffer, 16
.section .text
_start:
mov w0, 0 // acumulador de regalos
mov w1, 1 // día = 1
sumar_dias:
add w0, w0, w1 // total += día
add w1, w1, 1 // día++
cmp w1, 13
b.lt sumar_dias // mientras día < 13
// Convertir total a texto
ldr x1, =buffer
bl int_to_str
// Imprimir mensaje
ldr x1, =mensaje
bl imprimir
ldr x1, =buffer
bl imprimir
ldr x1, =nl
bl imprimir
// Salir del programa
mov x0, 0
mov x8, 93
svc 0
// -------------------------
// Imprimir cadena (x1)
// -------------------------
imprimir:
mov x0, 1
mov x2, 0
contar:
ldrb w3, [x1, x2]
cbz w3, imprimir_fin
add x2, x2, 1
b contar
imprimir_fin:
mov x8, 64
svc 0
ret
// -------------------------
// Convertir entero sin signo w0 a string (x1 buffer)
// -------------------------
int_to_str:
mov x2, 15
add x1, x1, x2
mov w3, 10
conv:
udiv w4, w0, w3
msub w5, w4, w3, w0
add w5, w5, '0'
strb w5, [x1], -1
mov w0, w4
cbnz w0, conv
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment