Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prob to resolv in Assembly IA32 for GAS

Status
Not open for further replies.

maisar

Programmer
Jan 14, 2010
1
0
0
PT
Hi!

I need to do, in IA32 Assembly for GAS, a program capable of
sort a vector of integers, and calculate the mean and median values of the vector.
The vector integers is initialized and has a fixed size of 20 elements, and the output data be made to the monitor.

I have an example, but does't work.

Can any body help me please??

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

"1 selectionSort :
2 beq $a1 , $zero , fimA # se array é vazio , retorna
3
4 # Itera por todos os elementos do array. Otimização : não iterar
indexando o array com o i, e sim iterar pelos endereços dos elementos
do array.
5 sll $t0 , $a1 , 2 # $t0 = tamanho * 4
6 add $t0 , $t0 , $a0 # $t0 = endereço de array [ tamanho ]
7
8 move $t7 , $a0 # endereço de array = endereço de array [0]
9
10 loopA :
11 move $t9 , $t7 # endereço de array [min] = endereço de array [i
]
12 lw $t4 , 0( $t9) # $t4 = array [ min]
13
14 # Procura pelo endereço do menor elemento , a partir do elemento seguinte
do cursor. Otimização usa a mesma otimização do loop externo : não
indexar com o j, e sim iterar pelos endereços.
15 addi $t8 , $t7 , 4 # endereço de array [j] = endereço de array [i
+1]
16 beq $t8 , $t0 , fimB # se endereço de array [j] == endereço de array
[ tamanho ], então não procura pois esse é o último elemento
17
18 loopB :
19 lw $t3 , 0( $t8) # $t3 = array [j]
20 slt $t5 , $t3 , $t4 # $t5 = array [j] < array [min ]
21 beq $t5 , $zero , fimIf # se array [j] >= array [min], continua o
loop
22
23 # Atualiza registradores que contém endereço e conteúdo de array [min]
24 move $t9 , $t8 # endereço de array [j] = endereço de array [min
]
25 lw $t4 , 0( $t9) # $t4 = array [ min]
26
27 fimIf :
28 addi $t8 , $t8 , 4 # incrementa endereço de array [j]
29 bne $t8 , $t0 , loopB # se endereço de array [j] != endereço de array
[ tamanho ], continua procurando menor
30
31 fimB :
32 # Troca o elemento atual do cursor com o menor elemento encontrado
33 lw $t6 , 0( $t7) # auxiliar = array
34 sw $t4 , 0( $t7) # array = array [min]
35 sw $t6 , 0( $t9) # array [min ] = auxiliar
36
37 addi $t7 , $t7 , 4 # incrementa endereço de array
38 bne $t7 , $t0 , loopA # continua iterando pelos elementos se
endereço de array != endereço de array [ tamanho ]
39
40 fimA :
41 jr $ra # Retorna. Neste momento , o array que está em
$a0 está ordenado
"


«««««««««««««««««««««««


Thkx!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top