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 - -
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
Get Answers For Free
Most questions answered within 1 hours.