write an arm subroutine which will extract a


Write an ARM subroutine which will extract a substring from a string. You will need to use the library routine malloc to allocate memory for the new string.

The subroutine signature is:

            char * mysubstring( char string[], int start, int end ) ;

 

where char string[] is the string to extract the substring from; it is passed into the ARM routine as a pointer in a1 to the first element of the character (byte) array,

int start is the first character to extract from the string to the substring; it is passed into the ARM routine as a value in a2,

int end is the last character to extract from the string to the substring; it is passed into the ARM routine as a value in a3.

The return is a pointer to the new string.

#include

#include

extern char * mysubstring( char string[], intstart, int end ) ;

int main( intargc, char * argv[] )

{

            chartosub[] = "this is the string to substring" ;

            char * result ; /* pointer to new string */

 

            result = mysubstring( tosub, 12, 17 ) ;

            printf( "String: %s\nSubstring: %s\n", tosub, result ) ;

 

            exit( 0 ) ;

}

To use the library routine malloc you need to calculate the number of bytes of memory you are requesting, put that number in a1 and blmalloc. Upon return from the library routine a1 will have a pointer to the allocated memory.

You may assume that the start and end values are within the string and  malloc returns a proper pointer value.

Request for Solution File

Ask an Expert for Answer!!
Application Programming: write an arm subroutine which will extract a
Reference No:- TGS0483659

Expected delivery within 24 Hours