Created
April 10, 2025 05:11
-
-
Save Joc193/aecc797821c08ec69a33f29b5cb79f3b 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 sus recíprocos aproximados | |
* Demostración: [ https://asciinema.org/ ] | |
* --------------------------------------------------------------------------------- | |
*/ | |
.global _start | |
.section .data | |
newline: .asciz "\n" | |
text: .asciz "1/" | |
buffer: .skip 20 | |
.section .text | |
_start: | |
mov x20, #1 | |
mov x21, #30 | |
loop: | |
cmp x20, x21 | |
bgt end | |
mov x0, x20 | |
bl int_to_ascii | |
mov x0, #1 | |
ldr x1, =buffer | |
mov x2, x22 | |
mov x8, #64 | |
svc #0 | |
mov x0, #1 | |
ldr x1, =text | |
mov x2, #2 | |
mov x8, #64 | |
svc #0 | |
fmov s0, #1.0 | |
scvtf s1, x20 | |
fdiv s2, s0, s1 | |
bl print_float | |
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 | |
print_float: | |
sub sp, sp, #16 // Reserva espacio en el stack | |
str s2, [sp] // Guarda el float a imprimir | |
mov x0, #1 // stdout | |
mov x1, sp // dirección del dato (no con ldr =sp) | |
mov x2, #8 // 8 bytes (float simple) | |
mov x8, #64 // syscall write | |
svc #0 | |
add sp, sp, #16 // Libera espacio del stack | |
ret | |
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 | |
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