Assembly language code in ARC (simplified SPARC code).
## Deliverables
In the main program, you CAN NOT load all of the array into the registers. You can only work with two elements of the array at a time. You can shorten the swap subroutine, by skipping the temporary (called temp) variable (since registers act as temporary variables anyway), if you want to. You must comment your code. Lastly, the swap subroutine must store the value of register 15 into a variable, as shown in class and store the array elements back into memory in the subroutine.
main () {
int a[10] = {10,8,6,4,2,9,7,5,3,1};
int I,j;
for (I=0; I<10; ++I) {
for (j=0; j<9; ++j) {
if (a[ j ] > a[ j+1 ]) {
swap ();
}
}
}
}
swap () {
int temp;
temp = a[ j ];
a[ j ] = a[ j+1];
a[ j+1] = temp;
}
Part 2:
main () {
int a[10], I, j;
for (I=0; I<10; I++) {
if (I==0) {
j =I;
sub3;
} else if (I <=5){
sub2;
} else {
sub1;
}
}
}
sub1 () {
j = I *2;
if ( j>=2 ) {
sub3;
} else {
j = 0;
sub3;
}
}
sub2 () {
j = I/2;
if (j <3) {
j = 0;
sub3;
} else {
sub3;
}
}
sub3 () {
a[I] = I +j;
}
## Platform
Assembly language code in ARC (simplified SPARC code).