Access Millions of academic & study documents

5 Write a program to reverse the contents of an array of 5 unsigned

Content type
User Generated
Showing Page:
1/3
5. Write a program to reverse the contents of an array of 5
unsigned 8-bit numbers starting at location $4000. For
example, if your initial array values read 2,4,3,6,1 they
must read 1,6,3,4,2 after you execute your program.
MUST BE WRITTEN IN HCS12 MICROPROCESSOR
LANGUAGE.
Solution
#include<stdio.h>
/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
int temp;
while (start < end)
{
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
}
/* Utility that prints out an array on a line */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", arr[i]);
printf(\"\ \");
}
/* Driver function to test above functions */
int main()
{
int arr[] = { 2, 4, 3, 6, 1};
printArray(arr, 6);
reverseArray(arr, 0, 5);
printf(\"Reversed array is \ \");
printArray(arr, 6);
return 0;
}
Run on IDE
Output:
2 4 3 6 1

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
5. Write a program to reverse the contents of an array of 5 unsigned 8-bit numbers starting at location $4000. For example, if your initial array values read 2,4,3,6,1 they must read 1,6,3,4,2 after you execute your program. MUST BE WRITTEN IN HCS12 MICROPROCESSOR LANGUAGE. Solution #include /* Function to reverse arr[] from start to end*/ void rvereseArray(int arr[], int start, int end) { int temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } /* Utility that prints out an array on a line */ void printArray(int arr[], int size) { int i; for (i=0; i < size; i++) printf(\"%d \", arr[i]); printf(\"\ \"); } /* Driver function to test above functions */ int main() { int arr[] = { 2, 4, 3, 6, 1}; printArray(arr, 6); reverseArray(arr, 0, 5); printf(\"Reversed array is \ \"); printArray(arr, 6); return 0; } Run on IDE Outpu ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4