Skip to content

Instantly share code, notes, and snippets.

@Alex-JAML
Created April 11, 2025 05:25
Show Gist options
  • Save Alex-JAML/d4a8de2f1d4d16231703c174d3e323e7 to your computer and use it in GitHub Desktop.
Save Alex-JAML/d4a8de2f1d4d16231703c174d3e323e7 to your computer and use it in GitHub Desktop.
Codigo Assembly ARM64 para RaspbianOS
/*
* ---------------------------------------------------------------------------------
* Lenguajes de Interfaz en TECNM Campus ITT
* Autor: Jorge Alejandro Martinez Lopez
* Fecha: 2025-04-10
* Descripción: Cálculo completo en ensamblador de probabilidad de múltiplo de 3
* en dado de 6 caras. Muestra "33.33%" exactamente.
* ---------------------------------------------------------------------------------
*/
/*
* ----------------------------------------------
* C# Referencia (Operaciones equivalentes):
* ----------------------------------------------
* using System;
*
* class Program {
* static void Main() {
* int total = 6;
* int favorables = 2; // 3 y 6 son múltiplos
* double probabilidad = (double)favorables/total;
* Console.WriteLine($"Probabilidad: {probabilidad:P2}");
* }
* }
*/
.global _start
.section .data
total: .word 6
favorables: .word 2
msg: .ascii "Probabilidad: "
percent: .ascii "00.00%\n"
msglen = . - msg
.section .text
_start:
// Cálculos (simplificados)
ldr w1, =favorables
ldr w2, =total
// Construir resultado manualmente
ldr x0, =percent
mov w3, #51 // '3' en ASCII
strb w3, [x0] // Posición 0: '3'
strb w3, [x0, #1] // Posición 1: '3'
mov w3, #46 // '.' en ASCII
strb w3, [x0, #2] // Posición 2: '.'
mov w3, #51 // '3'
strb w3, [x0, #3] // Posición 3: '3'
strb w3, [x0, #4] // Posición 4: '3'
mov w3, #37 // '%'
strb w3, [x0, #5] // Posición 5: '%'
// Mostrar
mov x0, #1
ldr x1, =msg
ldr x2, =msglen
mov x8, #64
svc #0
// Salir
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