-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEjercicio_39.s
156 lines (128 loc) · 3.08 KB
/
Ejercicio_39.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Lenguajes de Interfaz - Actividad 39
# Invertir los elementos de un arreglo
# Alumno: Gómez Aguilar Jared Emmanuel
# Número de Control: 22210309
# Python y Ensamblador
# Manipulación de arreglos
# ---------------------------
/*
def reverse_array(arr):
return arr[::-1]
*/
# ---------------------------
// Gómez Aguilar Jared Emmanuel
// 22210309
.global _start
.section .data
msg1: .ascii "Arreglo original: "
len1 = . - msg1
msg2: .ascii "\nArreglo invertido: "
len2 = . - msg2
array: .quad 1, 2, 3, 4, 5 // Arreglo a invertir
size = (. - array) / 8 // Tamaño del arreglo
buffer: .skip 32 // Buffer para conversión
space: .ascii " "
newline: .ascii "\n"
.section .text
_start:
// Imprimir mensaje inicial
mov x0, #1
ldr x1, =msg1
mov x2, len1
mov x8, #64
svc #0
// Mostrar arreglo original
bl mostrar_arreglo
// Invertir arreglo
bl invertir_arreglo
// Imprimir mensaje de arreglo invertido
mov x0, #1
ldr x1, =msg2
mov x2, len2
mov x8, #64
svc #0
// Mostrar arreglo invertido
bl mostrar_arreglo
// Imprimir nueva línea
mov x0, #1
ldr x1, =newline
mov x2, #1
mov x8, #64
svc #0
// Salir
mov x0, #0
mov x8, #93
svc #0
invertir_arreglo:
// Guardar enlace de retorno
str x30, [sp, #-16]!
// Preparar índices
mov x9, #0 // Índice inicial
mov x10, size // Tamaño total
sub x10, x10, #1 // Índice final (tamaño - 1)
ldr x11, =array // Dirección base del arreglo
loop_invertir:
// Verificar si terminamos
cmp x9, x10
bge fin_invertir
// Cargar valores
ldr x12, [x11, x9, lsl #3] // Valor inicio
ldr x13, [x11, x10, lsl #3] // Valor final
// Intercambiar valores
str x13, [x11, x9, lsl #3]
str x12, [x11, x10, lsl #3]
// Actualizar índices
add x9, x9, #1
sub x10, x10, #1
b loop_invertir
fin_invertir:
// Restaurar enlace de retorno
ldr x30, [sp], #16
ret
mostrar_arreglo:
// Guardar enlace de retorno
str x30, [sp, #-16]!
// Inicializar
mov x9, #0 // Índice
ldr x10, =array // Dirección base
mov x11, size // Tamaño
loop_mostrar:
// Verificar si terminamos
cmp x9, x11
bge fin_mostrar
// Cargar número actual
ldr x12, [x10, x9, lsl #3]
// Convertir a string
ldr x13, =buffer
mov x14, x12
mov x15, #0 // Contador de dígitos
convertir:
mov x16, #10
udiv x17, x14, x16
msub x18, x17, x16, x14
add x18, x18, #'0'
strb w18, [x13, x15]
add x15, x15, #1
mov x14, x17
cbnz x14, convertir
// Imprimir número
mov x0, #1
mov x1, x13
mov x2, x15
mov x8, #64
svc #0
// Imprimir espacio
mov x0, #1
ldr x1, =space
mov x2, #1
mov x8, #64
svc #0
// Siguiente número
add x9, x9, #1
b loop_mostrar
fin_mostrar:
// Restaurar enlace de retorno
ldr x30, [sp], #16
ret
ASCIINEMA REC
https://asciinema.org/a/690859