Question: Write a full MIPS that behaves exactly like the following C program. The following C code shows the proposed algorithm. The string is traversed with

Write a full MIPS that behaves exactly like the following C program.

The following C code shows the proposed algorithm. The string is traversed with two indices, called old_index and new_index, where the latter always takes a value less or equal to the former. When a non-space character is found, the character at position old_index is copied to position new_index, and both indices are incremented. When a space is found, the current character is not copied, and only old_index is incremented. The algorithm stops when a null character is found.

Write a full MIPS that behaves exactly like the following C program.

#include int main() // Read string char s1001; printf("Enter string: "); gets (s); //Remove spaces char c; int old-index = 0; int new-index = 0; do //Read character c = s[old-index]; // old position moves ahead old_index++; // If it's a space, ignore if(c=-'') continue; /7 Copy character new-index] = c; // New position moves ahead new_index++; } while (c); // Print result printf("New string: %s ", s)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!