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

This assignment involves the design and implementation of a MIPS assembly progra

ID: 3531147 • Letter: T

Question

This assignment involves the design and implementation of a MIPS assembly program that compares two null-terminated strings. String Comparison: Write and test a MIPS assembly language program (strcmp.asm) that extracts two null-terminated strings from the user and then performs a lexicographical comparison on the strings. Your program should print a message appropriate to the result of the comparison (i.e. 'stringA = stringB', 'stringA < stringB', or 'stringA > stringB'). Assume a maximum string length of 35 characters for the two input strings. Note, to extract a string from standard input, you must allocate a character array large enough to store the string plus the terminating null character.

Explanation / Answer


As expected,strlen(str1)is equal to 11, and it is null-terminated.

Where does C++ put the null terminator, if all 11 elements of the above char array are filled with the characters "hello world"? Is it actually allocating an array of length 12 instead of 11, with the 12th character being''?CPlusPlus.comseems to suggest that one of the 11 would need to be'', unless it is indeed allocating 12.

Suppose I do the following:

This outputsStr2: hello worldatcomY?

      char* str1 = "hello world";  

As expected,strlen(str1)is equal to 11, and it is null-terminated.

Where does C++ put the null terminator, if all 11 elements of the above char array are filled with the characters "hello world"? Is it actually allocating an array of length 12 instead of 11, with the 12th character being''?CPlusPlus.comseems to suggest that one of the 11 would need to be'', unless it is indeed allocating 12.

Suppose I do the following:

      // Create a new char array  char* str2 = (char*) malloc( strlen(str1) );    // Copy the first one to the second one  strncpy( str2, str1, strlen(str1) );    // Output the second one  cout << "Str2: " << str2 << endl;  

This outputsStr2: hello worldatcomY?

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