Logo 
Search:

Assembly Language Forum

Ask Question   UnAnswered
Home » Forum » Assembly Language       RSS Feeds

Assemble Language Subroutine

  Asked By: Tharun    Date: Apr 05    Category: Assembly Language    Views: 402
  

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 <stdio.h>
#include <stdlib.h>

extern char * mysubstring(char string[], int from, int to);

int main( int argc, char * argv[] )
{
char tosub[] = "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 bl malloc. 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.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Assemble Language Subroutine Or get search suggestion and latest updates.




Tagged: