Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function in ARM assembly language which will insert a string into anothe

ID: 3759766 • Letter: W

Question

Write a function in ARM assembly language which will insert a string into another string at a specific location. The function is:

char * csinsert( char * s1, char * s2, int loc ) ;

The function has a pointer to s1 in a1, a pointer to s2 in a2, and an integer in a3 as to where the insertion takes place. The function returns a pointer in a1 to the new string.

/* C language driver for string insert */

#include <stdio.h>

extern char * csinsert( char * s1, char * s2, int loc ) ;

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

{

                  char * s1 = "String 1 are combined" ;

                  char * s2 = " and string 2 " ;

                  int loc = 8 ;

                  char * result ;

                 

                  result = csinsert( s1, s2, loc ) ;

                  printf( "Result: %s ", result ) ;

                 

}

You can use the library functions strlen and malloc.

strlen has as input the pointer to the string in a1 and returns the length in a1.

malloc will allocate space for the new string where a1 on input is the size in bytes of the space requested and on output a1 is a pointer to the requested space.

Remember the registers a1-a4 do not retain their values across function calls.

Explanation / Answer

#include <stdio.h>

extern char * csinsert( char * s1, char * s2, int loc ) ;
int main( int argc, char * argv[] )
{
char * s1 = "String 1 are combined" ;
char * s2 = " and string 2 " ;
int loc = 8 ;
char * result ;

result = csinsert( s1, s2, loc ) ;
printf( "Result: %s ", result ) ;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote