Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago