Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called ‘ ReplaceLetterWithAsterisk’ that takes two arguments as

ID: 3589044 • Letter: W

Question

Write a function called ReplaceLetterWithAsterisk’ that takes two arguments as inputs. Use the MIPS calling convention; use $a registers to pass the arguments to your function. The first argument contains the string address and the second argument contains the character to replace. The ReplaceLetterWithAsterisk function will then find all instances of the letter in your string and replace them with an asterisk.

Here is sample output from the program: Please enter your string string Manipulation Tables and Simple Function Calls Please enter the character to replace: this is the input this is the input Here is the output STRNG mAN*PULAT*ON tABLES AND s*MPLE FUNCT* ON CALLS Please make sure your output line contains the string "Here is the outputi sample output. as shown in the Hint 1: Each character of a string is a byte. We need a character buffer (memory space) to hold the input string in memory. To declare memory space for a 63-byte string and its null terminator, you car use the following code: .data sone.strangws space. 64

Explanation / Answer

Given below is the program to replace a search letter with * . However in the output shown in questin, the characters also converted in case. Since the question has asked for only replace function, I have given the program with fucntion to replace a given letter with *. Hope it helps. If it helped, please don't forget to rate it. Thank you.


.data
str: .space 64
prompt1: .asciiz "Please enter your string: "
prompt2: .asciiz "Please endter the character to replace: "
msg: .asciiz " Here is the output: "
.text
#prompt for string
li $v0, 4
la $a0, prompt1
syscall
#get string input from user
li $v0, 8
la $a0, str
li $a1, 63
syscall
#prompt for the search characters
li $v0, 4
la $a0, prompt2
syscall
#get char input from user and store in $t0
li $v0, 12
syscall
move $t0, $v0
#setup parameters for calling ReplaceLetterWithAsterisk
la $a0, str #address of string
move $a1, $t0 #search character
jal ReplaceLetterWithAsterisk
#display the output
li $v0, 4
la $a0, msg
syscall
li $v0, 4
la $a0, str
syscall
#exit
li $v0, 10
syscall
#-----------------------------------
ReplaceLetterWithAsterisk:
move $t0, $a0 #t0 = address of string
move $t1, $a1 #t1 = search char
li $t3, '*' #t3 = '*'
loop:
lb $t2, ($t0) #get current char
beq $t2, '', end_loop #if null terminator , goto end_loop
bne $t2, $t1, next #compare current char to search char, if not equal, go to next
#they are equal here, so replace with *
sb $t3, ($t0) #store * to the current addresss, to replace current char
next:
addi $t0, $t0, 1 #increment address
b loop
end_loop:
jr $ra

output

Please enter your string:
String Manipulation Tables and Simple Function Calls
Please endter the character to replace:
i
Here is the output: Str*ng Man*pulat*on Tables and S*mple Funct*on Calls

-- program is finished running --

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote