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

I am using AT&T style assembly instruction Write a C-callable assembler version

ID: 3808265 • Letter: I

Question

I am using AT&T style assembly instruction

Write a C-callable assembler version of the library strcpy function called mystrcpy (to avoid conflicts with the library version) that copies the contents of one string to a user provided array and returns a pointer to the provided array. The function prototype is:

char *mystrcpy(char *s, char *ct);

Write your code in a source file named strcpy.s. The provided C driver (strcpyc.c) takes user entered input for the source string and checks both the pointer returned and the effect of the copy. Choose test cases that exercise different possibilities in the logic of your code, e.g. a null string. What would happen if you choose a string longer than the destination array in the Cdriver?

Explanation / Answer

Firstly, We need to create a Mystrcpy function for copying the string that points to by source which terminates the null byte to the specified buffer to the destination.


I have written the Mystrcopy function which describes the copies of contents of one string to a user provided array and will give the result a pointer to the specified data. It includes the code along with the comments.

Code:-

// copy the entire contents from the array
char * Mystrcpy (char *s, char *ct)
{
// It helps to check certain conditions at given run time
assert ((s! = NULL) && (ct! = NULL));
// create a charcter array
char *pRst = s;
// using do-while loop
do
{
* s + + = * ct;
}
while (* ct + +);
// return the array
return pRst;
}


Next step is to create a strcpy function which enables user to enter the source string and displays the result at the console.

Code:-

// Declartion of void method

void strcpy(char *s, char *ct)

{
  
// Creating a char array

char source[25];
     
   // Tell user to enter the source string
     
printf("Enter your source string ");
  
// It reads the source string from the user-input
  
scanf("%s", source);
  
printf("Your source string is %s ", source);
  
// It displays the source string result in the console
  
return 0;
}

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