Last active
April 10, 2025 23:55
-
-
Save FranciscoJCE/e18923f5ec86cca5996f233930fe6bfb 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
| /* | |
| * Programa: Numero en la serie Fibonacci usando un algoritmo. | |
| * Autor: Francisco Javier Crisostomo Enciso | |
| * Descripción: Encuentra y muestra todos los números primos < 100 | |
| * Ejemplo en C#: | |
| * Console.Write("Ingrese un número: "); | |
| * int num = int.Parse(Console.ReadLine()); | |
| * int a = 0, b = 1; | |
| * while (b < num) { | |
| * int temp = a + b; | |
| * a = b; | |
| * b = temp; | |
| * } | |
| * Console.WriteLine(b == num ? "Sí es Fibonacci" : "No es Fibonacci"); | |
| * ASCIINEMA:https://asciinema.org/a/N5ZZK8xqFfmNIxs7o76KWeJoN | |
| */ | |
| .section .data | |
| prompt: .asciz "Ingrese un número: " | |
| si_msg: .asciz "Sí es Fibonacci\n" | |
| no_msg: .asciz "No es Fibonacci\n" | |
| newline: .asciz "\n" | |
| .section .bss | |
| .lcomm input_buffer, 16 | |
| .lcomm number, 4 | |
| .section .text | |
| .global _start | |
| _start: | |
| // Mostrar prompt | |
| mov x0, #1 | |
| ldr x1, =prompt | |
| mov x2, #18 | |
| mov x8, #64 | |
| svc #0 | |
| // Leer entrada del usuario | |
| mov x0, #0 | |
| ldr x1, =input_buffer | |
| mov x2, #16 | |
| mov x8, #63 | |
| svc #0 | |
| // Convertir entrada a número | |
| ldr x1, =input_buffer | |
| bl atoi | |
| ldr x2, =number | |
| str w0, [x2] // Guardar número ingresado | |
| // Verificar si es Fibonacci | |
| mov w1, #0 // a = 0 | |
| mov w2, #1 // b = 1 | |
| mov w3, w0 // n = número ingresado | |
| fib_loop: | |
| cmp w2, w3 | |
| b.eq found_fib | |
| b.gt not_fib | |
| // Calcular siguiente número Fibonacci | |
| add w4, w1, w2 // c = a + b | |
| mov w1, w2 // a = b | |
| mov w2, w4 // b = c | |
| b fib_loop | |
| found_fib: | |
| // Mostrar "Sí es Fibonacci" | |
| mov x0, #1 | |
| ldr x1, =si_msg | |
| mov x2, #17 | |
| mov x8, #64 | |
| svc #0 | |
| b exit | |
| not_fib: | |
| // Mostrar "No es Fibonacci" | |
| mov x0, #1 | |
| ldr x1, =no_msg | |
| mov x2, #18 | |
| mov x8, #64 | |
| svc #0 | |
| exit: | |
| // Salir | |
| mov x8, #93 | |
| mov x0, #0 | |
| svc #0 | |
| // ------------------------------------------------------------ | |
| // Función: atoi | |
| // Convierte string ASCII a entero (similar a atoi en C) | |
| // Entrada: x1 = dirección del string | |
| // Salida: w0 = número convertido | |
| // ------------------------------------------------------------ | |
| atoi: | |
| mov w0, #0 // resultado = 0 | |
| mov w2, #10 // base 10 | |
| atoi_loop: | |
| ldrb w3, [x1], #1 // cargar byte y avanzar puntero | |
| cmp w3, #10 // '\n' | |
| beq atoi_done | |
| cmp w3, #13 // '\r' | |
| beq atoi_done | |
| cmp w3, #'0' | |
| blt atoi_done | |
| cmp w3, #'9' | |
| bgt atoi_done | |
| // Convertir dígito y acumular | |
| sub w3, w3, #'0' // convertir ASCII a dígito | |
| madd w0, w0, w2, w3 // resultado = resultado * 10 + dígito | |
| b atoi_loop | |
| atoi_done: | |
| ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment