Created
April 11, 2025 06:26
-
-
Save Alex-JAML/80bc0cb202d65d6aed7c0540e21533b9 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: Determina si un número entero es divisible entre 2 y 5 | |
| * Demostración: [ASCIINEMA.ORG/XXXXXX] | |
| * --------------------------------------------------------------------------------- | |
| */ | |
| /* | |
| * ---------------------------------------------- | |
| * C# "Divisibilidad" (Referencia) | |
| * ---------------------------------------------- | |
| * using System; | |
| * | |
| * class Program { | |
| * static void Main() { | |
| * Console.Write("Ingrese un número entero: "); | |
| * int num = int.Parse(Console.ReadLine()); | |
| * | |
| * bool div2 = (num % 2 == 0); | |
| * bool div5 = (num % 5 == 0); | |
| * | |
| * if (div2 && div5) { | |
| * Console.WriteLine("El número es divisible entre 2 y 5"); | |
| * } else { | |
| * Console.WriteLine("El número NO es divisible entre 2 y 5"); | |
| * } | |
| * } | |
| * } | |
| */ | |
| .global _start | |
| .section .data | |
| prompt: .asciz "Ingrese un número entero: " | |
| len_prompt = . - prompt | |
| buffer: .space 32 | |
| len_buffer = . - buffer | |
| si_msg: .asciz "El número es divisible entre 2 y 5\n" | |
| len_si = . - si_msg | |
| no_msg: .asciz "El número NO es divisible entre 2 y 5\n" | |
| len_no = . - no_msg | |
| .section .text | |
| _start: | |
| // Mostrar prompt | |
| mov x0, #1 | |
| adrp x1, prompt | |
| add x1, x1, :lo12:prompt | |
| mov x2, len_prompt | |
| mov x8, #64 | |
| svc #0 | |
| // Leer entrada del usuario | |
| mov x0, #0 | |
| adrp x1, buffer | |
| add x1, x1, :lo12:buffer | |
| mov x2, len_buffer | |
| mov x8, #63 | |
| svc #0 | |
| // Convertir entrada a entero (x19 = número) | |
| adrp x1, buffer | |
| add x1, x1, :lo12:buffer | |
| mov x19, #0 | |
| mov x20, #10 | |
| convert_loop: | |
| ldrb w2, [x1], #1 | |
| cmp w2, #10 // Verificar newline | |
| beq check_div | |
| sub w2, w2, #'0' // Convertir ASCII a número | |
| madd x19, x19, x20, x2 // x19 = x19*10 + digito | |
| b convert_loop | |
| check_div: | |
| // Verificar divisibilidad entre 2 (último bit = 0) | |
| tst x19, #1 | |
| bne no_divisible | |
| // Verificar divisibilidad entre 5 (último dígito 0 o 5) | |
| mov x0, x19 | |
| mov x1, #5 | |
| udiv x2, x0, x1 | |
| msub x3, x2, x1, x0 // x3 = x0 % x1 | |
| cbnz x3, no_divisible | |
| // Es divisible | |
| mov x0, #1 | |
| adrp x1, si_msg | |
| add x1, x1, :lo12:si_msg | |
| mov x2, len_si | |
| mov x8, #64 | |
| svc #0 | |
| b exit | |
| no_divisible: | |
| mov x0, #1 | |
| adrp x1, no_msg | |
| add x1, x1, :lo12:no_msg | |
| mov x2, len_no | |
| mov x8, #64 | |
| svc #0 | |
| exit: | |
| // 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