Question: Reverse The Values In The Array The test function accepts two arguments, arr, the start address of an array, and n the size of the

Reverse The Values In The Array
The test function accepts two arguments, arr, the start address of an array, and n the size of the array. Reverse all the elements in the array. Thus, if the array contained:
183100
the reversed array would contain:
100381
Register, r12, can also be used as temporary variable. r0 contains the start of arr, r1 contains n. No value is returned.
.arch armv4
.syntax unified
.arm
.text
.align 2
.type test, %function
.global test
test:
mov r12, r0
sub r2,r1,#1
top:
cmp r12, r2
bge done
ldr r3,[r0, r12, lsl #2]
ldr r4,[r0, r2, lsl #2]
str r3,[r0, r2, lsl #2]
str r4,[r0, r12, lsl #2]
add r12, r12, #1
sub r2,r2, #1
b top
done:
mov pc, lr
correct this code of mine , not working
test bench:
#include
#include
static void my_test(int arr[], int n)
{
int i =0;
n = n -1;
int t1, t2;
while ( i < n ){
t1= arr[i];
t2= arr[n];
arr[i]= t2;
arr[n]= t1;
i++;
n--;
}
}
extern void test(int arr[], int n);
int test_harness( void )
{
int arr1[20], arr2[20];
int res, expected;
for( int i =0; i <20; i++){
arr1[i]= arr2[i]= rand()%20;
}
test(arr1,8);
my_test(arr2,8);
for( int i =0; i <8; i++){
res = arr1[i];
expected = arr2[i];
if ( res != expected ){
printf("at i=%d expected %d, got %d
", i, expected, res );
return 1;
}
}
printf("passed test1
");
for( int i =0; i <20; i++){
arr1[i]= arr2[i]= rand()%20;
}
test(arr1,17);
my_test(arr2,17);
for( int i =0; i <17; i++){
res = arr1[i];
expected = arr2[i];
if ( res != expected ){
printf("at i=%d expected %d, got %d
", i, expected, res );
return 1;
}
}
printf("passed test2
");
return 0;
}
Recursive Maximum

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!