Created
April 11, 2025 06:37
-
-
Save Alex-JAML/396e0d606470b68b9bbfac0f3c04849f 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: Cálculo de probabilidad binomial para exactamente 3 caras en 5 lanzamientos | |
| * Implementación ARMv8 con operaciones reales en ensamblador | |
| * Matemáticas: C(5,3)*(0.5)^5 = 10/32 = 31.25% | |
| * Registros: x0-x2 para direcciones, w0-w14 para valores y cálculos | |
| * --------------------------------------------------------------------------------- | |
| */ | |
| /* | |
| * ---------------------------------------------- | |
| * C# Referencia (Operaciones equivalentes): | |
| * ---------------------------------------------- | |
| * using System; | |
| * | |
| * class Program { | |
| * static int Combinatoria(int n, int k) { | |
| * if (k == 0 || k == n) return 1; | |
| * return Combinatoria(n-1, k-1) + Combinatoria(n-1, k); | |
| * } | |
| * | |
| * static void Main() { | |
| * int lanzamientos = 5; | |
| * int exitos = 3; | |
| * double prob = (double)Combinatoria(lanzamientos, exitos) | |
| * / Math.Pow(2, lanzamientos); | |
| * Console.WriteLine($"Probabilidad exacta: {prob:P2}"); | |
| * } | |
| * } | |
| */ | |
| .global _start | |
| .section .data | |
| // Valores precalculados | |
| C5_3: .word 10 // Combinatoria(5,3) | |
| potencia2: .word 32 // 2^5 | |
| factor100: .word 100 // Conversión a porcentaje | |
| // Mensaje de resultado | |
| msg: .ascii "Probabilidad exacta: " | |
| resultado: .ascii "31.25%\n" | |
| msglen = . - msg | |
| .section .text | |
| _start: | |
| // ====================== | |
| // 1. Carga de valores | |
| // ====================== | |
| ldr x0, =C5_3 // Cargar dirección de C(5,3) | |
| ldr w0, [x0] // w0 = 10 | |
| ldr x1, =potencia2 // Cargar dirección de 2^5 | |
| ldr w1, [x1] // w1 = 32 | |
| ldr x2, =factor100 // Cargar dirección de factor | |
| ldr w2, [x2] // w2 = 100 | |
| // ====================== | |
| // 2. Cálculo principal | |
| // ====================== | |
| // (10 * 100) / 32 = 31.25 | |
| mul w3, w0, w2 // w3 = 10 * 100 = 1000 | |
| udiv w4, w3, w1 // w4 = 1000 / 32 = 31 (parte entera) | |
| mul w5, w4, w1 // w5 = 31 * 32 = 992 | |
| sub w6, w3, w5 // w6 = 1000 - 992 = 8 (resto) | |
| // Cálculo decimal: (8 * 100) / 32 = 25 | |
| mul w6, w6, w2 // w6 = 8 * 100 = 800 | |
| udiv w7, w6, w1 // w7 = 800 / 32 = 25 (decimal) | |
| // ====================== | |
| // 3. Conversión a ASCII | |
| // ====================== | |
| // Parte entera (31) | |
| mov w8, #10 | |
| udiv w9, w4, w8 // w9 = 31 / 10 = 3 (decenas) | |
| msub w10, w9, w8, w4 // w10 = 31 - 30 = 1 (unidades) | |
| add w9, w9, #48 // '3' | |
| add w10, w10, #48 // '1' | |
| // Parte decimal (25) | |
| udiv w11, w7, w8 // w11 = 25 / 10 = 2 (décimos) | |
| msub w12, w11, w8, w7 // w12 = 25 - 20 = 5 (centésimos) | |
| add w11, w11, #48 // '2' | |
| add w12, w12, #48 // '5' | |
| // ====================== | |
| // 4. Construir resultado | |
| // ====================== | |
| ldr x13, =resultado | |
| strb w9, [x13] // '3' | |
| strb w10, [x13, #1] // '1' | |
| mov w14, #46 // '.' | |
| strb w14, [x13, #2] // '.' | |
| strb w11, [x13, #3] // '2' | |
| strb w12, [x13, #4] // '5' | |
| mov w14, #37 // '%' | |
| strb w14, [x13, #5] // '%' | |
| // ====================== | |
| // 5. Mostrar resultado | |
| // ====================== | |
| mov x0, #1 // stdout | |
| ldr x1, =msg // Mensaje | |
| mov x2, msglen // Longitud | |
| mov x8, #64 // sys_write | |
| svc #0 | |
| // ====================== | |
| // 6. Terminar programa | |
| // ====================== | |
| mov x0, #0 // Código de salida | |
| mov x8, #93 // sys_exit | |
| svc #0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment