MARS MIPS simulator #A†list is defined here .data my_array: .word 38, 3, 71, 16,
ID: 3766332 • Letter: M
Question
MARS MIPS simulator
#A†list is defined here
.data
my_array: .word 38, 3, 71, 16, 12, 4, 8, 1, 18, 83
.text
la $s0, my_array # based address of list loaded into $s0
addi $s1, $zero, 10 # $s1 is set to the size of the list
# Now you have the size and the base address of the list
# You should be able to reverse the numbers in list
# Continue to write your code here
Explanation / Answer
.data
Size: .word 10 # Size is 10
my_array: .word 38, 3, 71, 16, 12, 4, 8, 1, 18, 83 # my_array[10]={1,2,..}
.text
main:
la $t1, Size # get the address of variable Size
la $t2, my_array # get the address of variable my_array
lw $t3, 0($t1) # fetch the value of Size to register $t3
sra $t4, $t3, 1 # right shift arithematic, now $t4 contains Size/2
sll $t3, $t3, 2 # left shift logic, now $t3 contains Size*4
loop:
addi $t7, $t7, -4 # moves pointer backwards
lw $t5, 0($t2)
lw $t0, 0($t7)
sw $t5, ($t7) # interchange
sw $t0, ($t2) # contents
addi $t2, $t2, 4 # moves pointer forward
ble $t2, $t7, loop
end:
la $t0, my_array # get the address of my_array to $t0
la $t1, Size # get the address of Size to $t1
lw $t3, 0($t1) # get Size to $t3
sll $t3, $t3, 2 # left shift logic, now $t3 contains Size*4
add $t1, $t0, $t3 # $t1=my_array+Size*4 => array bound
li $v0, 1 # service 1 is print integer
lab4:
lw $a0, 0($t0) # load desired value into argument register $a0
syscall # print the value in $a0
addi $t0, $t0, 4 # increase array index
bne $t0, $t1, lab4 # check if reach array bound
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.