Last active
April 9, 2025 00:23
-
-
Save Joc193/c0995fd8118b2309bb6d72f2a7d6fea3 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 los enteros del 9 al 43 | |
* Demostración: [ https://asciinema.org/a/9la2WDnWckKkRCXrdTRcNVk85 ] | |
* --------------------------------------------------------------------------------- | |
*/ | |
.global _start | |
.section .data | |
newline: .asciz "\n" | |
buffer: .skip 20 | |
.section .text | |
_start: | |
mov x20, #9 | |
mov x21, #43 | |
loop: | |
cmp x20, x21 | |
bgt end | |
mov x0, x20 | |
bl int_to_ascii | |
// escribir en pantalla | |
mov x0, #1 // stdout | |
ldr x1, =buffer // dirección del buffer | |
mov x2, x22 // longitud del número convertido | |
mov x8, #64 // syscall write | |
svc #0 | |
// salto de línea | |
mov x0, #1 | |
ldr x1, =newline | |
mov x2, #1 | |
mov x8, #64 | |
svc #0 | |
add x20, x20, #1 | |
b loop | |
end: | |
mov x0, #0 | |
mov x8, #93 | |
svc #0 | |
// Convertir entero a ASCII en buffer | |
int_to_ascii: | |
mov x1, x0 // backup número | |
ldr x2, =buffer | |
add x2, x2, #19 | |
mov x22, #0 | |
itoa_loop: | |
mov x3, #10 | |
udiv x4, x1, x3 | |
msub x5, x4, x3, x1 | |
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