Skip to content

Instantly share code, notes, and snippets.

@ulisetrejo250
Created April 9, 2025 06:23
Show Gist options
  • Save ulisetrejo250/280c287898d2687ab555e61a45c71e77 to your computer and use it in GitHub Desktop.
Save ulisetrejo250/280c287898d2687ab555e61a45c71e77 to your computer and use it in GitHub Desktop.
Codigo Assembly ARM64 Hola Mundo para RaspbianOS
/*
* ---------------------------------------------------------------------------------
* Lenguajes de Interfaz en TECNM Campus ITT
* Autor: [TREJO DENA ULISES ]
* Fecha: [08/04/2025]
* Descripción: Tabla de multiplicar del 1 al 12 usando ARM64 Assembly en Raspbian.
* Demostración: [ ASCIINEMA.ORG/.....]
* ---------------------------------------------------------------------------------
*/
.global _start
.section .bss
buffer: .skip 32 // Buffer para convertir número a string
.section .data
newline: .asciz "\n"
times: .asciz " x "
equal: .asciz " = "
.section .text
_start:
mov x19, #1 // i = 1
outer_loop:
cmp x19, #13
beq end_program
mov x20, #1 // j = 1
inner_loop:
cmp x20, #13
beq next_i
// Convertir i a string
mov x0, x19
bl print_int
// Imprimir " x "
ldr x0, =times
bl print_str
// Convertir j a string
mov x0, x20
bl print_int
// Imprimir " = "
ldr x0, =equal
bl print_str
// Calcular resultado i * j y mostrarlo
mul x0, x19, x20
bl print_int
// Imprimir salto de línea
ldr x0, =newline
bl print_str
add x20, x20, #1
b inner_loop
next_i:
add x19, x19, #1
b outer_loop
end_program:
mov x0, #0
mov x8, #93
svc #0
// -----------------------------------------------
// Rutina: print_int
// Entrada: x0 = número
// Salida: imprime número como string en stdout
print_int:
ldr x9, =buffer + 31 // apuntar al final
mov x2, x0 // copia del número
mov x3, x9
print_loop:
mov x4, #10
udiv x5, x2, x4 // x5 = x2 / 10
msub x6, x5, x4, x2 // x6 = x2 - (x5 * 10) = x2 % 10
add x6, x6, #'0' // convertir a ASCII
sub x1, x1, #1
strb w6, [x3]
mov x2, x5
cmp x2, #0
bne print_loop
// Calcular longitud
mov x2, x9
sub x2, x2, x3
// Imprimir usando syscall write
mov x1, x3
mov x0, #1
mov x8, #64
svc #0
ret
// -----------------------------------------------
// Rutina: print_str
// Entrada: x0 = dirección del string null-terminated
print_str:
mov x1, x0
mov x2, #0
count_len:
ldrb w3, [x1, x2]
cmp w3, #0
beq do_print
add x2, x2, #1
b count_len
do_print:
mov x1, x0
mov x8, #93
mov x0, #1
svc #0
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment