Question

MIPS ASSEMBLY Have the user input a string and then be able to make changes to...

MIPS ASSEMBLY

Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample runs). In order to work with characters, we need to remember that each ASCII character is stored using a single byte. So, we will now add in the instructions load byte (lb) and store byte (sb) in order to manipulate our character information.

Requirements:

● While you can set how long the string can be at maximum, you can’t tell the user a specific length that the string must be (e.g. Enter a string of length 10) and you can’t ask them how long the string is.

● After you have their string, you will prompt them to see if they want to make any changes. If they do, then read in the character that they want to change in the string and then the character that they want to change it to. o All characters of the same type in the string can be affected, not just a single one of them. So, if they choose to change the spaces to dashes, all spaces are affected. (See sample run 2)

● After each change print the current string out to them and ask if they want to make another change.

● When they are finished making changes, print the final string and then exit the program properly.

Sample Output: (The prompt: followed by the output)

This program reads in a String from the user and then allows the user to make changes to it until they want to stop.

Please enter your string now (maximum of 40 characters): We can input a fairly long string.

Your current string is: We can input a fairly long string.

Do you want to make any changes to the string? (Y/N): Y

Enter the character in the string would you like replaced: i

Enter what you would like to change the character to: 1

Your current string is:

We can 1nput a fa1rly long str1ng.

Do you want to make any changes to the string? (Y/N): Y

Enter the character in the string would you like replaced: a

Enter what you would like to change the character to: @

Your current string is: We c@n 1nput @ f@1rly long str1ng.

Do you want to make any changes to the string? (Y/N): N

Your final string is: We c@n 1nput @ f@1rly long str1ng.

-- program is finished running –

This program reads in a String from the user and then allows the user to make changes to it until they want to stop.

Please enter your string now (maximum of 40 characters): A short one too.

Your current string is: A short one too.

Do you want to make any changes to the string? (Y/N): Y

Enter the character in the string would you like replaced: Enter what you would like to change the character to: =

Your current string is: A-short-one-too.

Do you want to make any changes to the string? (Y/N): N

Your final string is: A-short-one-too.

-- program is finished running --

This program reads in a String from the user and then allows the user to make changes to it until they want to stop.

Please enter your string now (maximum of 40 characters): We could change nothing.

Your current string is: We could change nothing.

Do you want to make any changes to the string? (Y/N): N

Your final string is: We could change nothing.

- - programs finished running - -

Homework Answers

Answer #1

Please give positive ratings for my effort. Thanks.

PROGRAM

.LC0:

        .ascii  "Please enter your string now (maximum of 40 characters) "

        .ascii  ":  \000"

.LC1:

        .ascii  "\012Your current string is :  \012\000"

.LC2:

        .ascii  "\012Do you want to make any changes to the string? (Y/N)"

        .ascii  " :  \000"

.LC3:

        .ascii  "\012Enter the character in the string would you like rep"

        .ascii  "laced :  \000"

.LC4:

        .ascii  "\012Enter what you would like to change the character to"

        .ascii  " :  \000"

main:

        daddiu  $sp,$sp,-80

        sd      $31,72($sp)

        sd      $fp,64($sp)

        sd      $28,56($sp)

        sd      $16,48($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(main)))

        daddiu  $2,$fp,8

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev)($28)

        move    $25,$2

        nop

        ld      $2,%got_page(.LC0)($28)

        daddiu  $5,$2,%got_ofst(.LC0)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,8

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZSt7getlineIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE)($28)

        move    $25,$2

        nop

        ld      $2,%got_page(.LC1)($28)

        daddiu  $5,$2,%got_ofst(.LC1)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        move    $3,$2

        daddiu  $2,$fp,8

        move    $5,$2

        move    $4,$3

        ld      $2,%call16(_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE)($28)

        move    $25,$2

        nop

        ld      $5,%got_disp(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)($28)

        move    $4,$2

        ld      $2,%call16(_ZNSolsEPFRSoS_E)($28)

        move    $25,$2

        nop

.L7:

        ld      $2,%got_page(.LC2)($28)

        daddiu  $5,$2,%got_ofst(.LC2)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,40

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_)($28)

        move    $25,$2

        nop

        lb      $3,40($fp)

        li      $2,89                 # 0x59

        beq     $3,$2,.L2

        nop

        lb      $3,40($fp)

        li      $2,121                  # 0x79

        bne     $3,$2,.L3

        nop

.L2:

        ld      $2,%got_page(.LC3)($28)

        daddiu  $5,$2,%got_ofst(.LC3)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,41

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_)($28)

        move    $25,$2

        nop

        ld      $2,%got_page(.LC4)($28)

        daddiu  $5,$2,%got_ofst(.LC4)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,42

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_)($28)

        move    $25,$2

        nop

        sw      $0,0($fp)

.L6:

        lw      $16,0($fp)

        daddiu  $2,$fp,8

        move    $4,$2

        ld      $2,%call16(_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv)($28)

        move    $25,$2

        nop

        sltu    $2,$16,$2

        andi    $2,$2,0x00ff

        beq     $2,$0,.L4

        nop

        lw      $3,0($fp)

        daddiu  $2,$fp,8

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $3,0($2)

        lb      $2,41($fp)

        xor     $2,$3,$2

        sltu    $2,$2,1

        andi    $2,$2,0x00ff

        beq     $2,$0,.L5

        nop

        lw      $3,0($fp)

        daddiu  $2,$fp,8

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        move    $3,$2

        lb      $2,42($fp)

        sb      $2,0($3)

.L5:

        lw      $2,0($fp)

        addiu   $2,$2,1

        sw      $2,0($fp)

        b       .L6

        nop

.L4:

        ld      $2,%got_page(.LC1)($28)

        daddiu  $5,$2,%got_ofst(.LC1)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        move    $3,$2

        daddiu  $2,$fp,8

        move    $5,$2

        move    $4,$3

        ld      $2,%call16(_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE)($28)

        move    $25,$2

        nop

        ld      $5,%got_disp(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)($28)

        move    $4,$2

        ld      $2,%call16(_ZNSolsEPFRSoS_E)($28)

        move    $25,$2

        nop

        b       .L7

        nop

.L3:

        daddiu  $2,$fp,8

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        move    $2,$0

        b       .L11

        nop

        move    $16,$4

        daddiu  $2,$fp,8

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        move    $2,$16

        move    $4,$2

        ld      $2,%call16(_Unwind_Resume)($28)

        move    $25,$2

        nop

.L11:

        move    $sp,$fp

        ld      $31,72($sp)

        ld      $fp,64($sp)

        ld      $28,56($sp)

        ld      $16,48($sp)

        daddiu  $sp,$sp,80

        j       $31

        nop

__static_initialization_and_destruction_0(int, int):

        daddiu  $sp,$sp,-48

        sd      $31,40($sp)

        sd      $fp,32($sp)

        sd      $28,24($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        move    $3,$4

        move    $2,$5

        sll     $3,$3,0

        sw      $3,0($fp)

        sll     $2,$2,0

        sw      $2,4($fp)

        lw      $3,0($fp)

        li      $2,1                        # 0x1

        bne     $3,$2,.L14

        nop

        lw      $3,4($fp)

        li      $2,65535                    # 0xffff

        bne     $3,$2,.L14

        nop

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $4,$2,%got_ofst(_ZStL8__ioinit)

        ld      $2,%call16(_ZNSt8ios_base4InitC1Ev)($28)

        move    $25,$2

        nop

        ld      $6,%got_disp(__dso_handle)($28)

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $5,$2,%got_ofst(_ZStL8__ioinit)

        ld      $4,%got_disp(_ZNSt8ios_base4InitD1Ev)($28)

        ld      $2,%call16(__cxa_atexit)($28)

        move    $25,$2

        nop

.L14:

        nop

        move    $sp,$fp

        ld      $31,40($sp)

        ld      $fp,32($sp)

        ld      $28,24($sp)

        daddiu  $sp,$sp,48

        j       $31

        nop

_GLOBAL__sub_I_main:

        daddiu  $sp,$sp,-32

        sd      $31,24($sp)

        sd      $fp,16($sp)

        sd      $28,8($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(_GLOBAL__sub_I_main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(_GLOBAL__sub_I_main)))

        li      $5,65535                    # 0xffff

        li      $4,1                        # 0x1

        ld      $2,%got_page(__static_initialization_and_destruction_0(int, int))($28)

        daddiu  $2,$2,%got_ofst(__static_initialization_and_destruction_0(int, int))

        move    $25,$2

        nop

        move    $sp,$fp

        ld      $31,24($sp)

        ld      $fp,16($sp)

        ld      $28,8($sp)

        daddiu  $sp,$sp,32

        j       $31

        nop

DW.ref.__gxx_personality_v0:

IMAGE OF PORGRAM

IMAGE OF OUTPUT

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
Write a MIPS assembly program that asks the user first for a string, then for a...
Write a MIPS assembly program that asks the user first for a string, then for a character. The program should search the string for the character and print out the number of times the character appears in the string. Restrictions can be used, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Write a Python program to ask user input of a string, then ask user input of...
Write a Python program to ask user input of a string, then ask user input of what letters they want to remove from the string. User can either put in "odd", "even" or a number "n" that is greater than 2. When user input "odd", it will remove the characters which have odd numbers in the sequence of the string. When user input "even", it will remove the characters which have even numbers in the sequence of the string. When...
3. Create a program which allows the user to swap individual words in an input string....
3. Create a program which allows the user to swap individual words in an input string. Given a string of input, your program should count and store the number of words in a 2D array. The user can then select the index of the words they want to swap. Your program should swap those two words and then print the entire string to ouput. • Use string prompt "> ". • Use indices prompt "Enter two indices: ". • Remove...
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a Java application a String input by the user and shows whether the string contains...
Write a Java application a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. needs, at minimum, asl user to input for the String, then...
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...