Question: Using only at most r 0 , r 1 , r 2 , and r 3 , return the middle value of r 0 ,

Using only at most r0, r1, r2, and r3, return the middle value of r0, r1, and r2.
test bench:
#include
int middle( int r0, int r1, int r2){
int t;
if ( r2< r1){
t = r2; r2= r1; r1= t;
}
if ( r2< r0){
t = r2; r2= r0; r0= t;
}
r0= r0< r1? r1 : r0;
return r0;
}
extern int test(int r0, int r1, int r2);
int test_harness( void )
{
int expected, res;
expected = middle(1,2,3);
res = test(1,2,3);
if ( res != expected ){
printf("expected %d, got %d
", expected, res );
return 1;
}
else {
printf("passed test1
");
}
expected = middle(3,1,2);
res = test(3,1,2);
if ( res != expected ){
printf("expected %d, got %d
", expected, res );
return 1;
}
else {
printf("passed test2
");
}
expected = middle(2,3,1);
res = test(2,3,1);
if ( res != expected ){
printf("expected %d, got %d
", expected, res );
return 1;
}
else {
printf("passed test3
");
}
return 0;
}
my work:
.arch armv4
.syntax unified
.arm
.text
.align 2
.global test
.type test, %function
test:
cmp r0,r1
movgt r3,r0
movle r3,r1
cmp r3,r2
movle r3,r2
cmp r3,r2
moveq r3,r0
cmp r3,r1
movle r0,r3
movgt r3,r1
mov r0,r3
mov pc, lr
not getting the correct value
solve the question based on this test bench and my work(change what need to change)
make sure the middle value 2 is the answer
don't use any previous answer or AI generated answers

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!