Question: Write an ARM assembly language routine that accepts two C strings, concatenates them and returns a pointer to the concatenated version to the calling C

Write an ARM assembly language routine that accepts two C strings, concatenates them and returns a pointer to the concatenated version to the calling C driver program to be printed.

The assembly routine should have the definition:

extern char * jstring( char * buf1, char * buf2 )

where buf1 is a pointer to the first string and buf2 is a pointer to the second string.

A string in C is a byte array with the last byte equal to zero.

The return to the C program will be the pointer to the newly allocated space where the strings are concatenated.

The driver program in C is:

/* C driver program for joining strings */

#include

#include

extern char * jstring( char * buf1, char * buf2 ) ;

int main( int argc, char * argv[] )

{

char buffer1[] = "First part of string" ;

char buffer2[] = " join this to buffer1 " ;

char * result ;

result = jstring( buffer1, buffer2 ) ;

printf( "Concatenated strings: %s ", result ) ;

exit( 0 ) ;

}

You will need to determine the lengths of the two strings passed in. This can be done using the library routine strlen for each string. To find the length of the string the register a1 should have the pointer to the string. bl to the library routine ( bl strlen ). Upon return a1 will have the length of the string in bytes not counting the null byte at the end.

To obtain memory for the concatenated strings you use the library function malloc.

This subroutine has as its input in a1 the number of bytes requested. The return is in a1 and is a pointer to the space. For example, to obtain 30 bytes:

mov a1, #30

bl malloc

;a1 now has a pointer to a 30 byte space

You must calculate the space needed in the ARM subroutine.

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!