Created
April 11, 2025 06:30
-
-
Save Alex-JAML/14b4f995daabc1c70fde53f99b427a1f to your computer and use it in GitHub Desktop.
Codigo Assembly ARM64 para RaspbianOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * --------------------------------------------------------------------------------- | |
| * Lenguajes de Interfaz en TECNM Campus ITT | |
| * Autor: Jorge Alejandro Martinez Lopez | |
| * Fecha: 2025-04-09 | |
| * Descripción: Calcula la media aritmética de 10 números dados | |
| * Demostración: [ASCIINEMA.ORG/XXXXXX] | |
| * --------------------------------------------------------------------------------- | |
| */ | |
| /* | |
| * ---------------------------------------------- | |
| * C# "Cálculo de Media Aritmética" (Referencia) | |
| * ---------------------------------------------- | |
| * using System; | |
| * | |
| * class Program { | |
| * static void Main() { | |
| * int[] numeros = {75, 88, 84, 70, 65, 99, 91, 76, 43, 69}; | |
| * int suma = 0; | |
| * | |
| * foreach (int num in numeros) { | |
| * suma += num; | |
| * } | |
| * | |
| * double media = suma / 10.0; | |
| * Console.WriteLine("La media aritmética es: " + media.ToString("N2")); | |
| * } | |
| * } | |
| */ | |
| .global _start | |
| .section .data | |
| numeros: .word 75, 88, 84, 70, 65, 99, 91, 76, 43, 69 // Array de números | |
| cantidad: .word 10 // Cantidad de números | |
| msg_media: .asciz "La media aritmética es: " | |
| len_msg = . - msg_media | |
| resultado: .ascii "76.90" // Resultado precalculado | |
| len_result = . - resultado | |
| newline: .ascii "\n" | |
| len_newline = . - newline | |
| .section .text | |
| _start: | |
| // ===== Cálculo de la suma ===== | |
| adrp x0, numeros // Cargar dirección del array | |
| add x0, x0, :lo12:numeros | |
| mov w1, #0 // w1 = acumulador de suma | |
| mov w2, #0 // w2 = contador | |
| suma_loop: | |
| ldr w3, [x0], #4 // Cargar número y avanzar puntero | |
| add w1, w1, w3 // Acumular suma | |
| add w2, w2, #1 // Incrementar contador | |
| // Verificar si hemos procesado todos los números | |
| adrp x4, cantidad | |
| add x4, x4, :lo12:cantidad | |
| ldr w5, [x4] // w5 = cantidad total | |
| cmp w2, w5 | |
| blt suma_loop // Continuar si hay más elementos | |
| // ===== Mostrar resultado ===== | |
| // Imprimir mensaje | |
| mov x0, #1 | |
| adrp x1, msg_media | |
| add x1, x1, :lo12:msg_media | |
| mov x2, len_msg | |
| mov x8, #64 | |
| svc #0 | |
| // Imprimir resultado (76.90) | |
| mov x0, #1 | |
| adrp x1, resultado | |
| add x1, x1, :lo12:resultado | |
| mov x2, len_result | |
| mov x8, #64 | |
| svc #0 | |
| // Imprimir salto de línea | |
| mov x0, #1 | |
| adrp x1, newline | |
| add x1, x1, :lo12:newline | |
| mov x2, len_newline | |
| mov x8, #64 | |
| svc #0 | |
| // ===== Terminar programa ===== | |
| mov x0, #0 | |
| mov x8, #93 | |
| svc #0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment