[Solved] CMI Assignment 3- Sorting One-Dimensional Arrays

$25

File Name: CMI_Assignment_3-_Sorting_One-Dimensional_Arrays.zip
File Size: 452.16 KB

SKU: [Solved] CMI Assignment 3- Sorting One-Dimensional Arrays Category: Tag:
5/5 - (1 vote)

Create an ARMv8 assembly language program that implements the following algorithm:

#define SIZE 50

int main()

{

int v[SIZE], i, j, min, temp;

/* Initialize array to random positive integers, mod 256 */

for (i = 0; i < SIZE; i++) {

v[i] = rand() & 0xFF;

printf(v[%d]: %d
, i, v[i]);

}

/* Sort the array using a selection sort */

for (i = 0; i < SIZE 1; i++) {

/* Find the least element in the right subarray */

min = i;

for (j = i + 1; j < SIZE; j++) {

/* Compare elements */

if (v[j] < v[min])

min = j;

}

/* Swap elements */

temp = v[min];

v[min] = v[i];

v[i] = temp;

}

/* Print out the sorted array */

printf(
Sorted array:
);

for (i = 0; i < SIZE; i++)

printf(v[%d]: %d
, i, v[i]);

return 0;

}

Create space on the stack to store all local variables, using the techniques described in lectures. Use m4 macros or assembler equates for all stack variable offsets. Optimize your code so that it uses as few instructions as possible. Be sure, however, that you always read or write memory when using or assigning to the local variables. Name the program assign3.asm.

Also run the program in gdb, first displaying the contents of the array before sorting, and then displaying it again once the sort is complete (use the x command to examine memory). You should show that the algorithm is working as expected. Capture the gdb session using the script UNIX command, and name the output file script.txt.

Other Requirements

Make sure your code is readable and fully documented, including identifying information at the top of each file. You must comment each line of assembly code. Your code should also be well designed: make sure it is well organized, clear, and concise.

New Skills Needed for this Assignment:

  • Use of the stack to store local variables
  • Addressing stack variables
  • Use of m4 macros or assembler equates for stack variable offsets
  • Storing and addressing one-dimensional arrays on the stack

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CMI Assignment 3- Sorting One-Dimensional Arrays
$25