Created
April 10, 2025 05:54
-
-
Save Joc193/ef2aed86655e12a1f77de769cabd54ca 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-09 | |
* Descripción: Imprimir potencias de 2 hasta un máximo de 1000 | |
* Demostración: [ https://asciinema.org/ ] | |
* --------------------------------------------------------------------------------- | |
*/ | |
.global _start | |
.section .data | |
newline: .asciz "\n" // Salto de línea | |
buffer: .skip 20 // Espacio para almacenar número como string | |
.section .text | |
_start: | |
mov x20, #1 // x20 = 2^0 = 1 | |
mov x21, #1000 // Límite: 1000 | |
loop: | |
cmp x20, x21 | |
bgt end // Si pasamos el 1000, salimos | |
mov x0, x20 // Convertimos x20 a string | |
bl int_to_ascii | |
// Imprimir número convertido | |
mov x0, #1 // stdout | |
ldr x1, =buffer // dirección del buffer | |
mov x2, x22 // longitud del número | |
mov x8, #64 // syscall write | |
svc #0 | |
// Imprimir salto de línea | |
mov x0, #1 | |
ldr x1, =newline | |
mov x2, #1 | |
mov x8, #64 | |
svc #0 | |
lsl x20, x20, #1 // x20 = x20 * 2 (siguiente potencia) | |
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 y lo guarda en buffer | |
// Devuelve longitud del string en x22 | |
// -------------------------------------------------------- | |
int_to_ascii: | |
mov x1, x0 // Copia del número | |
ldr x2, =buffer | |
add x2, x2, #19 // Apuntamos al final del buffer | |
mov x22, #0 // x22 = longitud | |
itoa_loop: | |
mov x3, #10 | |
udiv x4, x1, x3 | |
msub x5, x4, x3, x1 // x5 = x1 % 10 | |
add x5, x5, #'0' // Convertir dígito a ASCII | |
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