Created
April 10, 2025 05:32
-
-
Save Joc193/98cd0955e8730ca51db68cde044f894b to your computer and use it in GitHub Desktop.
Programas 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: Jocelyn Alvarez Paniagua | |
* Fecha: 2025-04-07 | |
* Descripción: Imprimir enteros del 1 al 30 con texto "1/" | |
* Demostración: [ ASCIINEMA.ORG/..... ] | |
* --------------------------------------------------------------------------------- | |
*/ | |
.global _start | |
.section .data | |
newline: .asciz "\n" // Salto de línea | |
texto: .asciz " 1/\n" // Texto fijo a mostrar después del número | |
buffer: .skip 20 // Espacio para convertir el entero a string | |
.section .text | |
_start: | |
mov x20, #1 // x20 = contador desde 1 | |
mov x21, #30 // x21 = límite superior | |
loop: | |
cmp x20, x21 | |
bgt end // Salir del bucle si x20 > 30 | |
// Imprimir número | |
mov x0, x20 | |
bl int_to_ascii | |
mov x0, #1 // stdout | |
ldr x1, =buffer // puntero a buffer | |
mov x2, x22 // longitud del número convertido | |
mov x8, #64 // syscall write | |
svc #0 | |
// Imprimir texto fijo: " 1/\n" | |
mov x0, #1 | |
ldr x1, =texto | |
mov x2, #4 | |
mov x8, #64 | |
svc #0 | |
add x20, x20, #1 // siguiente número | |
b loop | |
end: | |
mov x0, #0 | |
mov x8, #93 // syscall exit | |
svc #0 | |
// --------------------------------------------- | |
// Función: int_to_ascii | |
// Convierte el entero en x0 a string ASCII en `buffer` | |
// Guarda longitud en x22 | |
// --------------------------------------------- | |
int_to_ascii: | |
mov x1, x0 | |
ldr x2, =buffer | |
add x2, x2, #19 | |
mov x22, #0 | |
itoa_loop: | |
mov x3, #10 | |
udiv x4, x1, x3 // x4 = x1 / 10 | |
msub x5, x4, x3, x1 // x5 = x1 - (x4*10) => x1 % 10 | |
add x5, x5, #'0' | |
strb w5, [x2] | |
sub x2, x2, #1 | |
add x22, x22, #1 | |
mov x1, x4 | |
cmp x1, #0 | |
bne itoa_loop | |
add x2, x2, #1 | |
copy_ascii: | |
mov x3, #0 | |
ldr x5, =buffer | |
copy_loop: | |
ldrb w4, [x2, x3] | |
strb w4, [x5, x3] | |
add x3, x3, #1 | |
cmp x3, x22 | |
blt copy_loop | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment