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

The MIPS code below prints : 1 2 3 4 5 6 7 8 9 10 Please add a loop to the code

ID: 3543310 • Letter: T

Question

The MIPS code below prints : 1  2  3  4  5  6  7  8  9 10

Please add a loop to the code so that it prints : 1  2  3  4  5  6  7  8  9 10

                                                                 2  2  6  4  10  6  14  8 18 10


In other words, if an array element is odd then double it.


.data

Sz: .word 10

Array: .word  1, 2, 3, 4, 5, 6, 7, 8, 9,10

NL: .asciiz " "


.text

main:

lw $s7, Sz # get size of list

move $s1, $zero   # set counter for # of elems printed

move $s2, $zero   # set offset from Array


print_loop:

bge $s1, $s7, print_loop_end # stop after last elem is printed

lw $a0, Array($s2)    # print n ext value from the list

li $v0, 1

syscall

la $a0, NL # print a newline

li $v0, 4

syscall


addi $s1, $s1, 1 # increment the loop counter

addi $s2, $s2, 4 # step to the next array elem

j print_loop # repeat the loop

print_loop_end:

Explanation / Answer

please rate - thanks

any questions - ask





.data
Sz: .word 10
Array: .word 1, 2, 3, 4, 5, 6, 7, 8, 9,10
NL: .asciiz " "
Space: .asciiz " "
.text
main:
lw $s7, Sz # get size of list
move $s1, $zero # set counter for # of elems printed
move $s2, $zero # set offset from Array
print_loop:
bge $s1, $s7, print_loop_end # stop after last elem is printed
lw $a0, Array($s2) # print n ext value from the list
li $v0, 1
syscall
la $a0, Space # print a newline
li $v0, 4
syscall
addi $s1, $s1, 1 # increment the loop counter
addi $s2, $s2, 4 # step to the next array elem
j print_loop # repeat the loop
print_loop_end:
move $s1, $zero # set counter for # of elems printed
move $s2, $zero # set offset from Array
li $s3,1
la $a0, NL # print a newline
li $v0, 4
syscall
print_loop2:
bge $s1, $s7, print_loop_end2 # stop after last elem is printed
lw $a0, Array($s2) # print n ext value from the list
andi $a1,$a0,1
beqz $a1,output
sll $a0,$a0,1
output:
li $v0, 1
syscall
la $a0, Space # print a newline
li $v0, 4
syscall
addi $s1, $s1, 1 # increment the loop counter
addi $s2, $s2, 4 # step to the next array elem
j print_loop2 # repeat the loop
print_loop_end2:

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