Last active
April 11, 2025 06:50
-
-
Save Joc193/d2bfd451a0e790358159f665a055a253 to your computer and use it in GitHub Desktop.
Programa ARM64 - Imprimir el valor absoluto de -6, 0, 25, -143, -42.
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: Imprimir el valor absoluto de -6, 0, 25, -143, -42. | |
* Demostración: [ https://asciinema.org/a/bArAYLZyMJvcD1ZqM6a4Uk9YB ] | |
* --------------------------------------------------------------------------------- | |
*/ | |
.global _start | |
.section .data | |
numeros: .word -6, 0, 25, -143, -42 // Lista de enteros con signo | |
cantidad: .word 5 // Cantidad de elementos | |
newline: .asciz "\n" | |
buffer: .skip 20 | |
.section .text | |
_start: | |
ldr x19, =numeros // Puntero al arreglo | |
ldr w20, =5 // Número de elementos | |
mov w21, #0 // Índice actual | |
loop: | |
cmp w21, w20 | |
bge fin | |
ldr w22, [x19, w21, SXTW #2] // Cargar número con signo | |
cmp w22, #0 | |
b.ge es_positivo | |
neg w22, w22 // Si es negativo, obtener su valor absoluto | |
es_positivo: | |
mov w0, w22 | |
bl int_to_ascii | |
mov x0, #1 | |
ldr x1, =buffer | |
mov x2, x23 | |
mov x8, #64 | |
svc #0 | |
// salto de línea | |
mov x0, #1 | |
ldr x1, =newline | |
mov x2, #1 | |
mov x8, #64 | |
svc #0 | |
add w21, w21, #1 | |
b loop | |
fin: | |
mov x0, #0 | |
mov x8, #93 | |
svc #0 | |
// -------------------------------------------------------- | |
// Función: int_to_ascii | |
// Convierte número en w0 a string ASCII | |
// -------------------------------------------------------- | |
int_to_ascii: | |
mov w1, w0 | |
ldr x2, =buffer | |
add x2, x2, #19 | |
mov x23, #0 | |
itoa_loop: | |
mov w3, #10 | |
udiv w4, w1, w3 | |
msub w5, w4, w3, w1 | |
add w5, w5, #'0' | |
strb w5, [x2] | |
sub x2, x2, #1 | |
add x23, x23, #1 | |
mov w1, w4 | |
cmp w1, #0 | |
bne itoa_loop | |
add x2, x2, #1 | |
mov x3, #0 | |
ldr x5, =buffer | |
copy_ascii: | |
ldrb w6, [x2, x3] | |
strb w6, [x5, x3] | |
add x3, x3, #1 | |
cmp x3, x23 | |
blt copy_ascii | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment