Created
April 8, 2025 06:55
-
-
Save ulisetrejo250/90fefd25ddf847a0529b1a205d1d96d2 to your computer and use it in GitHub Desktop.
Codigo Assembly ARM64 Hola Mundo 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
.global _start | |
.section .data | |
mensaje: .ascii "Factorial: " | |
len = . - mensaje | |
newline: .asciz "\n" | |
.section .bss | |
.align 4 | |
buffer: .skip 32 // buffer seguro para conversión de número | |
.section .text | |
_start: | |
// Imprimir mensaje | |
mov x0, #1 | |
ldr x1, =mensaje | |
mov x2, len | |
mov x8, #64 | |
svc #0 | |
// Inicializar factorial | |
mov x1, #5 // Número base | |
mov x0, #1 // Resultado inicial | |
factorial_loop: | |
cmp x1, #1 | |
ble end_factorial | |
mul x0, x0, x1 | |
sub x1, x1, #1 | |
b factorial_loop | |
end_factorial: | |
// Convertir número en buffer | |
ldr x1, =buffer // Puntero al buffer | |
mov x2, #10 // Base 10 | |
convert_loop: | |
udiv x3, x0, x2 // Cociente | |
msub x4, x3, x2, x0 // Resto: x0 - (x3 * 10) | |
add x4, x4, #'0' // Convertir a ASCII | |
sub x1, x1, #1 | |
strb w4, [x1] | |
mov x0, x3 | |
cbz x0, print_number | |
b convert_loop | |
print_number: | |
// Imprimir desde buffer hasta final | |
ldr x0, =1 | |
ldr x2, =buffer + 32 // fin del buffer | |
sub x2, x2, x1 // longitud del número | |
mov x8, #64 | |
svc #0 | |
// Nueva línea | |
mov x0, #1 | |
ldr x1, =newline | |
mov x2, #1 | |
mov x8, #64 | |
svc #0 | |
// Salida | |
mov x0, #0 | |
mov x8, #93 | |
svc #0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment