Write an ARM function (subroutine) to count the number of odd integers in an int
ID: 3929764 • Letter: W
Question
Write an ARM function (subroutine) to count the number of odd integers in an integer array. The function signature is:
int numodd( int array[], int size ) ;
where:
int array[] is passed to the ARM function as a pointer to the first element of the integer array and,
int size is passed by value and is the number of elements in the array.
The C language source code is:
#include
#include
extern int numodd( int array[], int size ) ;
int main( int argc, char * argv[] )
{
int numarray[] = { 2, 3, 1025, 3024, 4057, -3, -1025, -3578 } ;
int size = sizeof(numarray) / sizeof( int ) ;
int result ;
result = numodd( numarray, size ) ;
printf( "Number of odd numbers: %d ", result ) ;
exit( 0 ) ;
}
A number is odd if the LSB is set (value = 1) and even if the LSB is reset (value = 0) .
Example Format:
.global numodd
.text
numodd:
stmfd sp!, {v1-v6,lr}
ldmfd sp!, {v1-v6,pc}
.end
Explanation / Answer
#include
#include
extern int numodd( int array[], int size ) ;
int main( int argc, char * argv[] )
{
int numarray[] = { 2, 3, 1025, 3024, 4057, -3, -1025, -3578 } ;
int size = sizeof(numarray) / sizeof( int ) ;
int result ;
result = numodd( numarray, size ) ;
printf( "Number of odd numbers: %d ", result ) ;
exit( 0 ) ;
}
A number is odd if the LSB is set (value = 1) and even if the LSB is reset (value = 0) .
Example Format:
.global numodd
.text
numodd:
stmfd sp!, {v1-v6,lr}
ldmfd sp!, {v1-v6,pc}
.end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.