Skip to content

Instantly share code, notes, and snippets.

@Joc193
Last active April 11, 2025 06:50
Show Gist options
  • Save Joc193/adbf493fd6439da76fe50421a388e661 to your computer and use it in GitHub Desktop.
Save Joc193/adbf493fd6439da76fe50421a388e661 to your computer and use it in GitHub Desktop.
Programa ARM64 - Calcular el promedio de las calificaciones de Nancy (95, 68, 92, 88).
/*
* ---------------------------------------------------------------------------------
* Lenguajes de Interfaz en TECNM Campus ITT
* Autor: Jocelyn Alvarez Paniagua
* Fecha: 2025-04-10
* Descripción: Calcular el promedio de las calificaciones de Nancy (95, 68, 92, 88).
* Demostración: [ https://asciinema.org/a/bArAYLZyMJvcD1ZqM6a4Uk9YB ]
* ---------------------------------------------------------------------------------
*/
.global _start
.section .data
mensaje: .asciz "El promedio de Nancy es: "
newline: .asciz "\n"
buffer: .skip 32
.section .text
_start:
// Sumar las calificaciones: 95 + 68 + 92 + 88 = 343
mov x20, #95
mov x21, #68
mov x22, #92
mov x23, #88
add x24, x20, x21 // x24 = 95 + 68
add x24, x24, x22 // x24 += 92
add x24, x24, x23 // x24 += 88 → total = 343
// Calcular el promedio (entero): promedio = total / 4
mov x1, #4
udiv x25, x24, x1 // x25 = promedio
// Imprimir mensaje
mov x0, #1
ldr x1, =mensaje
mov x2, #28
mov x8, #64
svc #0
// Convertir promedio a ASCII e imprimir
mov x0, x25
bl int_to_ascii
mov x0, #1
ldr x1, =buffer
mov x2, x23
mov x8, #64
svc #0
// Salto de línea
mov x0, #1
ldr x1, =newline
mov x2, #1
mov x8, #64
svc #0
// Salir
mov x0, #0
mov x8, #93
svc #0
// --------------------------------------------------------
// Función: int_to_ascii
// Convierte número en x0 a ASCII en 'buffer' y devuelve longitud en x23
// --------------------------------------------------------
int_to_ascii:
mov x1, x0
ldr x2, =buffer
add x2, x2, #31 // empezamos desde el final del buffer
mov x23, #0
itoa_loop:
mov x3, #10
udiv x4, x1, x3
msub x5, x4, x3, x1
add x5, x5, #'0'
strb w5, [x2]
sub x2, x2, #1
add x23, x23, #1
mov x1, x4
cmp x1, #0
bne itoa_loop
add x2, x2, #1
mov x3, #0
ldr x5, =buffer
copy_ascii:
ldrb w6, [x2, x3]
strb w6, [x5, x3]
add x3, x3, #1
cmp x3, x23
blt copy_ascii
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment