Last active
April 11, 2025 06:52
-
-
Save Joc193/7ffadd93e7698967015463c3b77c667a to your computer and use it in GitHub Desktop.
Programa ARM64 - Calcular la mediana de los números: 3, 7, 8, 12, 14.
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-10 | |
* Descripción: Calcular la mediana de los números: 3, 7, 8, 12, 14. | |
* Demostración: [ https://asciinema.org/a/bArAYLZyMJvcD1ZqM6a4Uk9YB ] | |
* --------------------------------------------------------------------------------- | |
*/ | |
.global _start | |
.section .data | |
msg: .asciz "La mediana es: " | |
newline: .asciz "\n" | |
nums: .word 3, 7, 8, 12, 14 // Datos ordenados | |
.section .bss | |
buffer: .skip 20 | |
.section .text | |
_start: | |
// Mostrar mensaje | |
ldr x0, =msg | |
bl print_string | |
// Calcular la mediana (posición 2 si se empieza desde 0) | |
ldr x1, =nums | |
ldr w0, [x1, #8] // 3*4 = byte offset → num[2] = 8 | |
bl int_to_ascii | |
// Nueva línea | |
ldr x0, =newline | |
bl print_string | |
// Salida | |
mov x8, #93 | |
mov x0, #0 | |
svc #0 | |
// ------------------------------- | |
print_string: | |
mov x1, x0 | |
mov x2, #0 | |
count_loop: | |
ldrb w3, [x1, x2] | |
cmp w3, #0 | |
beq write_str | |
add x2, x2, #1 | |
b count_loop | |
write_str: | |
mov x8, #64 | |
mov x1, x0 | |
mov x0, #1 | |
svc #0 | |
ret | |
// ------------------------------- | |
int_to_ascii: | |
mov x1, x0 | |
ldr x2, =buffer | |
add x2, x2, #19 | |
mov x3, #0 | |
mov x4, #0 | |
cmp x0, #0 | |
bge conv_loop | |
mov x4, #1 | |
neg x1, x1 | |
conv_loop: | |
mov x5, #10 | |
udiv x6, x1, x5 | |
msub x7, x6, x5, x1 | |
add x7, x7, #'0' | |
strb w7, [x2] | |
sub x2, x2, #1 | |
add x3, x3, #1 | |
mov x1, x6 | |
cmp x1, #0 | |
bne conv_loop | |
cmp x4, #1 | |
bne print_ascii | |
mov w7, #'-' | |
strb w7, [x2] | |
sub x2, x2, #1 | |
add x3, x3, #1 | |
print_ascii: | |
add x2, x2, #1 | |
mov x8, #64 | |
mov x0, #1 | |
mov x1, x2 | |
mov x2, x3 | |
svc #0 | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment