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.
main: # @main
push RBP
mov RBP, RSP
sub RSP, 144
lea RDI, QWORD PTR [.L.str]
mov DWORD PTR [RBP - 4], 0
mov DWORD PTR [RBP - 120], 0
mov DWORD PTR [RBP - 124], 0
mov AL, 0
call printf
lea RDI, QWORD PTR [RBP - 112]
mov DWORD PTR [RBP - 128], EAX # 4-byte Spill
call gets
mov QWORD PTR [RBP - 136], RAX # 8-byte Spill
.LBB0_1: # =>This Inner Loop Header: Depth=1
movsxd RAX, DWORD PTR [RBP - 120]
mov CL, BYTE PTR [RBP + RAX - 112]
mov BYTE PTR [RBP - 113], CL
mov EDX, DWORD PTR [RBP - 120]
add EDX, 1
mov DWORD PTR [RBP - 120], EDX
movsx EDX, BYTE PTR [RBP - 113]
cmp EDX, 32
jne .LBB0_3
jmp .LBB0_4
.LBB0_3: # in Loop: Header=BB0_1 Depth=1
mov AL, BYTE PTR [RBP - 113]
movsxd RCX, DWORD PTR [RBP - 124]
mov BYTE PTR [RBP + RCX - 112], AL
mov EDX, DWORD PTR [RBP - 124]
add EDX, 1
mov DWORD PTR [RBP - 124], EDX
.LBB0_4: # in Loop: Header=BB0_1 Depth=1
cmp BYTE PTR [RBP - 113], 0
jne .LBB0_1
lea RDI, QWORD PTR [.L.str1]
lea RSI, QWORD PTR [RBP - 112]
mov AL, 0
call printf
mov ECX, 0
mov DWORD PTR [RBP - 140], EAX # 4-byte Spill
mov EAX, ECX
add RSP, 144
pop RBP
ret
.L.str:
.asciz "Enter String:"
.L.str1:
.asciz "New string: %s \n"
Write a full MIPS that behaves exactly like the following C program. The following C code...
Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character. Here is an example input: I am an input string a b The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and...
The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...
Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...
Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will...
Write C programs named mystring.h and mystring.c, containing the headers and implementations of the following functions. int letter_count(char *s) computes and returns the number of English letters in string s. int word_count(char *s) computes and returns the number of words in string s. void lower_case(char *s) changes upper case to lower case of string s. void trim(char *s) removes the unnecessary empty spaces of string s. mystring.h #include <stdio.h> int letter_count(char *); void lower_case(char *); int word_count(char *); void trim(char...
Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...
Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified character in a string) Write a recursive function that finds the number of occurrences of a specified letter in a string using the following function header. int count(const string& s, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the...
Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...
Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining * if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: * result = is_palindrome(str, first_index, last_index) * * parameters - * str - the string to test * first_index -...