Code:
#include <stdlib.h>
#include <stdio.h>
#include<conio.h>
#define ARRAY_SIZE 10
void main()
{
int iarray[ARRAY_SIZE];
int x, y, holder;
clrscr();
printf("Enter 10 Array Elements :");
for(x=0;x<ARRAY_SIZE;x++)
scanf("%d",&iarray[x]);
printf("\nBefore Sort\n---------------\n");
for(x=0;x<ARRAY_SIZE;x++)
printf("%d ",iarray[x]);
//Bubble sort method
for(x = 0; x < ARRAY_SIZE; x++)
for(y = 0; y < ARRAY_SIZE-1; y++)
if(iarray[y] > iarray[y+1])
{
holder = iarray[y+1];
iarray[y+1] = iarray[y];
iarray[y] = holder;
}
printf("\n\nAfter Sort\n---------------\n");
for(x=0;x<ARRAY_SIZE;x++)
printf("%d ",iarray[x]);
getch();
}
Code:
.data
array: .word 10, 8, 1, 5, 2, 9, 4, 3, 7, 6
length: .word 10
main: la$ t3, array # put address of input into $t3
li $t2, 6 # put the index into $t2
add $t2, $t2, $t2 # double the index
add $t2, $t2, $t2 # double the index again (now 4X)
add $t1, $t2, $t3 # combine the two components of address
lw $t4, 0($t1) # get the value from array cell
li $v0, 1
move $a0, $t4
syscall
exit: li $v0, 10
syscall

