Professional Documents
Culture Documents
Project: CPEG 220 - Computer Organization and Architecture Fall 2021
Project: CPEG 220 - Computer Organization and Architecture Fall 2021
Fall 2021
Project
❑
100
1. Sorting Algorithm:
1
The sorting algorithm we chose to program is the selection sort. It works by finding the
minimum elements in an unsorted array and sorting it into an ascending order. The algorithm
takes an element as the minimum and compares it to every other element within the array and
swaps it if a smaller element is found thus creating a sorted list of arrays when it is finished with
all iterations.
2. Java Code :
public class SelectionSort
2
{
public static void main(String[] args)
{
int[] a = {12, 9, 15, 3, 7};
System.out.println("Array before sorting :");
for (int i=0;i<a.length;i++)
System.out.print(a[i] + " ");
for (int i=0;i<a.length-1;i++)
{
int min = i;
for (int j=i;j<a.length;j++)
if (a[j] < a[min])
min = j;
if (min != i)
{
int temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
System.out.println("\nArray after sorting :");
for (int i=0;i<a.length;i++)
System.out.print(a[i] + " ");
}
}
3
3. MIPS Assembly Code :
main:
lui $s0,0x1001 # $s0 = &A[0]
4
sll $t1,$t6,2 #$t1 = i*4
add $t1,$t1,$s0 #$t1 = &A[i]
lw $t0,0($t1) #$t0 = A[i]
.data
A: .word 12, 9, 15, 3, 7
5
4. Run and Test :
6
After the simulation: