Created
April 11, 2025 05:27
-
-
Save Alex-JAML/000927c7ee31d71ad050160453b43eb2 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-10 | |
| * Descripción: Cálculo de probabilidad de obtener al menos 2 cartas rojas | |
| * al seleccionar 4 cartas de un mazo de 52 (26 rojas/26 negras) | |
| * Matemáticas: Usa combinatoria para calcular casos favorables: | |
| * [C(26,2)*C(26,2) + C(26,3)*C(26,1) + C(26,4)] / C(52,4) | |
| * ≈ 69.63% | |
| * --------------------------------------------------------------------------------- | |
| */ | |
| /* | |
| * ---------------------------------------------- | |
| * C# Referencia (Operaciones equivalentes): | |
| * ---------------------------------------------- | |
| * using System; | |
| * | |
| * class Program { | |
| * static double Combinatoria(int n, int k) { | |
| * if (k > n) return 0; | |
| * if (k == 0 || k == n) return 1; | |
| * return Combinatoria(n-1, k-1) + Combinatoria(n-1, k); | |
| * } | |
| * | |
| * static void Main() { | |
| * int total = 52; | |
| * int rojas = 26; | |
| * int seleccion = 4; | |
| * | |
| * double casosTotales = Combinatoria(total, seleccion); | |
| * double casosFav = Combinatoria(rojas,2)*Combinatoria(total-rojas,2) | |
| * + Combinatoria(rojas,3)*Combinatoria(total-rojas,1) | |
| * + Combinatoria(rojas,4); | |
| * | |
| * double probabilidad = casosFav/casosTotales; | |
| * Console.WriteLine($"Probabilidad: {probabilidad:P2}"); | |
| * } | |
| * } | |
| */ | |
| .global _start | |
| .section .data | |
| // Valores precalculados para C(52,4) y combinaciones rojas | |
| C52_4: .quad 270725 // C(52,4) = 270725 | |
| C26_2: .quad 325 // C(26,2) = 325 | |
| C26_2x2: .quad 105625 // 325*325 = 105625 | |
| C26_3: .quad 2600 // C(26,3) = 2600 | |
| C26_1: .quad 26 // C(26,1) = 26 | |
| C26_3x1: .quad 67600 // 2600*26 = 67600 | |
| C26_4: .quad 14950 // C(26,4) = 14950 | |
| sumaFav: .quad 187175 // 105625 + 67600 + 14950 = 187175 | |
| factor: .quad 10000 // Para precisión decimal | |
| msg: .ascii "Probabilidad: " | |
| result: .ascii "69.63%\n" | |
| msglen = . - msg | |
| .section .text | |
| _start: | |
| // Cálculo de probabilidad (187175/270725 ≈ 0.6963) | |
| ldr x0, =sumaFav // Casos favorables | |
| ldr x0, [x0] | |
| ldr x1, =C52_4 // Casos totales | |
| ldr x1, [x1] | |
| ldr x2, =factor // Factor de escala | |
| ldr x2, [x2] | |
| // Multiplicar por 10000 para mantener decimales | |
| mul x0, x0, x2 // casosFav * 10000 | |
| udiv x3, x0, x1 // (casosFav*10000)/casosTotales | |
| // Convertir a porcentaje (dividir entre 100) | |
| mov x4, #100 | |
| udiv x5, x3, x4 // Parte entera (69) | |
| msub x6, x5, x4, x3 // Parte decimal (63) | |
| // Convertir a ASCII | |
| mov x7, #10 | |
| udiv x8, x5, x7 // Decenas (6) | |
| msub x9, x8, x7, x5 // Unidades (9) | |
| add x8, x8, #48 // '6' | |
| add x9, x9, #48 // '9' | |
| udiv x10, x6, x7 // Décimos (6) | |
| msub x11, x10, x7, x6 // Centésimos (3) | |
| add x10, x10, #48 // '6' | |
| add x11, x11, #48 // '3' | |
| // Construir resultado | |
| ldr x12, =result | |
| strb w8, [x12] // '6' | |
| strb w9, [x12, #1] // '9' | |
| mov w13, #46 // '.' | |
| strb w13, [x12, #2] // '.' | |
| strb w10, [x12, #3] // '6' | |
| strb w11, [x12, #4] // '3' | |
| mov w13, #37 // '%' | |
| strb w13, [x12, #5] // '%' | |
| // Mostrar resultado | |
| mov x0, #1 // stdout | |
| ldr x1, =msg // Mensaje | |
| mov x2, msglen // Longitud | |
| mov x8, #64 // sys_write | |
| svc #0 | |
| // Salir | |
| mov x0, #0 // Código 0 | |
| 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