Convert the following code into MIPS Assembly language: # You write code here to
ID: 3796957 • Letter: C
Question
Convert the following code into MIPS Assembly language:
# You write code here to implement the following C code.
# This will find the MIN ($s6) and MAX ($s7)
# in the array from A[0] through A[i].
# Note that you need to use lw to load A[j].
# while (j<=i)
# {
# if A[j]<MIN
# MIN=A[j];
# if A[j]>MAX
# MAX=A[j];
# j=j+1;
# }
***************************************************************************************
THIS CODE IS ALREADY GIVEN SO PLEASE USE IT!!!!:
.data
baseadd: .word 34, 5, 11, -12, 60, -2, 14, 71, 13, -27
string1: .asciiz "Index i [0~9]: "
string2: .asciiz " MIN="
string3: .asciiz " MAX="
.text
main:
# Input i to $s1
addi $v0, $zero, 4 # code for printing string is 4
la $a0, string1 # load address of string to be printed into $a0
syscall # call operating system
addi $v0, $zero, 5 # code for reading integer is 5
syscall # call operating system
add $s1, $v0, $zero # i in $s1
#baseadd of the array to $s5
la $s5, baseadd
#Load A[0] to initialize MIN ($s6) and MAX ($s7)
lw $s6, ($s5)
lw $s7, ($s5)
# initialize j=0 (j in $t1)
add $t1, $zero, $zero
Explanation / Answer
.data
baseadd: .word 34, 5, 11, -12, 60, -2, 14, 71, 13, -27
string1: .asciiz "Index i [0~9]: "
string2: .asciiz " MIN="
string3: .asciiz " MAX="
.text
main:
# Input i to $s1
addi $v0, $zero, 4 # code for printing string is 4
la $a0, string1 # load address of string to be printed into $a0
syscall # call operating system
addi $v0, $zero, 5 # code for reading integer is 5
syscall # call operating system
add $s1, $v0, $zero # i in $s1
#baseadd of the array to $s5
la $s5, baseadd
#Load A[0] to initialize MIN ($s6) and MAX ($s7)
lw $s6, ($s5)
lw $s7, ($s5)
# initialize j=0 (j in $t1)
add $t1, $zero, $zero