please solve all question. [25 pts] Write an MSP430 C function that implements b
ID: 3730368 • Letter: P
Question
please solve all question.
[25 pts]
Write an MSP430 C function that implements bubble sort of N words:
bubbleSort(short int *inpPtr, short int *outPtr, short int N)
2. [25 pts]
2.1 [20 pts] Write an MSP430 assembly subroutine bubbleSort that implements the same using R12 and
R13 as registers for source and destination addresses and R4 as the number of words to be sorted.
2.2 [5 pts] Modify bubbleSort to create a subroutine median that implements the median of N words
(for simplicity, assume N is odd), R14 should contain the output value.
3. [25 pts]
3.1 [20 pts] Write an MSP430 assembly subroutine addLong that adds two 32-bit signed numbers with
[R13:R12] and [R15:R14] holding the arguments with Little Endian convention, that is, R12 and R14
holding lower words (use the same convention for the remainder of this exam), output should be
stored in [R15:R13].
3.2 [5 pts] Modify addLong into another subroutine subLong that subtracts two 32-bit signed numbers
4. [25 pts] Write an MSP430 assembly routine mpyW that multiplies two 16-bit signed words with R12
and R13 holding input values and output should be stored in [R15:R14].
Explanation / Answer
#include <stdio.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("n");
}
int main()
{
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
printf("Sorted array: ");
printArray(arr, n);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.