$30
Implement a ‘replace’ program in MIPS assembly language that, given an array of integers Arr, its length, integers x and y, replaces all x with y in Arr. Then your program should print out all values of Arr.
For example, if Arr = {21, 20, 51, 83, 20, 20}, length = 6, x = 20, y = 5 and index = 0, then after running your program the values of Arr MUST be Arr = {21, 5 , 51, 83, 5 , 5} and the values MUST be printed out.
In the program, we assume the variables (e..g, Arr, length, x, y and index ) should be declared and initialized manually in the .data section.
Output: 21 5 51 83 5 5 (The first (i.e., before 21) or last (i.e., after the last 5) space can be negligible.)
NOTES: How to print Integers and Strings/space/newline using ‘syscall’
.data
x: .word 5
msg1: .asciiz "x=" nl: .asciiz "\n"
space: .asciiz " "
.text
main:
# Register assignments
# $s0 = x
# Initialize registers
# Print msg1
# Reg $s0 = x
li $v0, 4 la $a0, msg1
# Print result (x)
# print_string syscall code = 4
li $v0,1
# print_int syscall code = 1
move $a0, $s0
syscall
# Print newline
# Load integer to print in $a0
li $v0,4
la $a0, nl
syscall
# Exit
# print_string syscall code = 4
li $v0,10
syscall
# exit