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
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 an assembly program that reads characters from standard input until the “end of file” is...
Write an assembly program that reads characters from standard input until the “end of file” is reached. The input provided to the program contains A, C, T, and G characters. The file also may have new line characters (ASCII code 10 decimal), which should be skipped/ignored. The program then must print the count for each character. You can assume (in this whole assignment) that the input doe not contain any other kinds of characters.  the X86 assembly program that simply counts...
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...
Write a program that takes a string of characters (including spaces) as input, computes the frequency...
Write a program that takes a string of characters (including spaces) as input, computes the frequency of each character, sorts them by frequency, and outputs the Huffman code for each character.   When you are writing your program, you should first test it on a string of 7 characters, so you can check it. PLEASE NOTE: Your program must work for any text that has upper and lower case letters digits 0 - 9, commas, periods, and spaces. Please submit the...
COBOL Translate English to Pig Latin This interactive program translates any word the user enters into...
COBOL Translate English to Pig Latin This interactive program translates any word the user enters into Pig Latin. The interactive session --------------------------------------------- Enter any word to see what it looks like in Pig Latin. To quit, type Uitqay. --------------------------------------------- string The Pig Latin equivalent is: Ingstray --------------------------------------------- unstring The Pig Latin equivalent is: Unstringlay --------------------------------------------- Uitqay Oodbyegay! Specifications • If the word starts with a consonant, move the consonants before the first vowel to the end of the word and...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
a) sum = 0 for letter in '12345' : sum = sum + int(letter) print('sum =...
a) sum = 0 for letter in '12345' : sum = sum + int(letter) print('sum = ', sum) Write a program which reads a string containing any characters from the user and prints the sum of the digits in the string. For example, if the string from the user is "I want 3 oranges and 24 bananas', then the output would be 9, since 3 + 2 + 4 = 9. Note that a character C is a digit if...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A coffee order consists of a double price, a string for flavor, and characters for cream (Y/N), sugar (Y/N), and coffee size (S/M/L). Your main() function will call an order function that will ask the user for the flavor, size and whether or not they want cream or sugar. Your main() function will then create a coffee order structure and assign all of the values...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT