Reference no: EM13166265
Write an ARM assembly function that takes an array of integers and insures that all entries are positive. Remember the initial integer in the array is at index zero.
The C language program is:
/* absdriver.c - driver for absarray function */
#include <stdio.h>
#include <stdlib.h>
extern int absarray( int array[], int size ) ;
int main( int argc, char * argv[] )
{
int array[] = {1, 3, -5, -252, 280, -332 } ;
int asize = sizeof(array) / sizeof(int) ;
int result ;
int i ;
result = absarray( array, asize ) ;
for( i = 0 ; i < asize ; i++ )
printf( " %d ", array[i] ) ;
printf( "\n" ) ;
exit( 0 ) ;
}
The input to the ARM assembly language function is a pointer to the first element of the array in register a1. The size of the array is in a2 and is the number of integers. Remember an integer is 4 bytes long.
Recall that the ldr instruction does not affect the condition codes. Also consider the reverse subtract instruction, rsb.