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

Unrolling a MIPS loop. SOftware pipeline Problem A (9 Points) Unroll the followi

ID: 3603182 • Letter: U

Question

Unrolling a MIPS loop.
SOftware pipeline

Problem A (9 Points) Unroll the following MIPS loop and eliminate all stalls. You must unroll the code the minimum number of times such that all stalls are eliminated in the scheduled/transformed code that you produce. Only concentrate on the MIPS loop code; assume that appropriate initialization and termination code is available. You should assume the following: .The floating point functional units are pipelined. Normal MIPS forwarding. Branch resolved in ID stage. .Delayed branch. Assume the following latencies: FP ALU operation followed by FP ALU operation: 2 cycles. FP ALU operation followed by store of FP result: 1 cycles Load of FP operand followed by FP ALU operation: 1 cycle. .Starting addresses of the arrays are as follows: x-array - location 0, y-array - location 1000, z-array - location 2000, and w- array -location 3000 F0 has been initialized with the value of c. .RI has been initialized to refer to the first elements of the x, y, z and w arrays. C code: for (i = 0; i

Explanation / Answer

# Basic instructions
beq $t1, $t2, label
bne $t1, $t2, label
bgez $t1, label
bgtz $t1, label
blez $t1, label
bltz $t1, label

beqz $t1, label
bnez $t1, label
beq $t1, 123, label
bne $t1, 123, label
bge $t1, $t2, label
bgt $t1, $t2, label
bge $t1, 123, label
bgt $t1, 123, label
addi $t2, $t1, 3 # tmp = b + 3
blt $t0, $t2, then # if (a < tmp)
addi $t0, $t0, 2 # (else case) a = a + 2
j end
then: addi $t0, $t0, 1 # (then case) a = a + 1
end: add $t1, $t1, $t0
addi $t2, $t1, 3 # tmp = b + 3
blt $t0, $t2, then # if (a < tmp)
j end
then: addi $t0, $t0, 1 # (then case) a = a + 1
end: add $t1, $t1, $t0 # b = b + a

addi $t3, $t2, 4 # tmp = c + 4
loop: ble $t0, $t3, body # while (a <= tmp) goto body
j end # goto end
body: addi $t0, $t0, 3 # (in loop) a = a + 3
j loop # end loop, repeat
end: add $t1, $t1, $t0 # b = b + a

addi $t3, $t2, 4 # tmp = c + 4
loop: bgt $t0, $t3, end # if (a > tmp) goto end
addi $t0, $t0, 3 # (in loop) a = a + 3
j loop # end loop, repeat
end: add $t1, $t1, $t0 # b = b + a

li $t2, 0 # sum = 0
li $t1, 0 # i = 0
loop: bge $t1, $t0, end # (start loop) if i >= n goto end
add $t2, $t2, $t1 # sum = sum + i
addi $t1, $t1, 1 # i = i + 1
j loop # (end loop)
end: #

loop: ... # (begin loop)
bge $t0, $t1, else # if (a < b)
j end # (then branch) break
else: ... # (rest of loop body)
j loop # (end loop)
end

li $t1, 0 # (init) i = 0
loop: bge $t1, $t2, end # while (i < n)
rem $t3, $t1, 5 # tmp = i % 5
bgt $t3, 2, update # if (tmp > 2) continue
add $t0, $t0, $t1 # total += i
update: addi $t1, $t1, 1 # (update) i++
j loop # (end while)
end:

lw $t1, $t2 # $t1 = Memory[$t2]
sw $t1, $t2 # Memory[$t2] = $t1


lw $t1, label # $t1 = Memory[label]
lw $t1, label+4 # $t1 = Memory[label+4]
lw $t1, label($t2) # $t1 = Memory[label+$t2]
sw $t1, label # Memory[label] = $t1
sw $t1, label+4 # Memory[label+4] = $t1
sw $t1, label($t2) # Memory[label+$t2] = $t1

.data
fibs: .word 0, 1, 1, 2, 3, 5, 8, 13, 21, 35, 55, 89, 144
.text
li $t1, 0 # i = 0
loop: ... # (loop condition, TODO)
lw $t0, fibs($t1) # fib = fibs[i]
... # (loop body)
addi $t1, $t1, 4 # i++ <= +4
j loop # (end loop)

.data
fibs: .word 0, 1, 1, 2, 3, 5, 8, 13, 21, 35, 55, 89, 144
.text
li $t1, fibs # addr = fibs
loop: ... # (loop condition, TODO)
lw $t0, $t1 # fib = *addr
... # (loop body)
addi $t1, $t1, 4 # addr += 4
j loop # (end loop)

msg1: .asciiz"A program in MIPS to test for loop. "

.text

li $t0,10

la $a0,msg1
for_loop:
BLT $t0,1,Exit

li $v0,4
syscall
Sub $t0,$t0,1

j for_loop

Exit:
li $v0,10
syscall
msg1: .asciiz "Enter a number: "

.text

li $t1, 0 # temp var counter for loop
li $t2, 10 # exit condition
Loop:
beq $t2, $t1, Exit #at 10 we go to Exit, defined below
addi $t1, $t1, 1 #increment counter
syscall #calls service 33, playing music
j Loop #jumps back to the top of loop

Exit: #ends the program
li $v0,10 #loads the service that exits
syscall
li $v0,4
la $a0,msg1

while:

syscall
li $v0,5
syscall
bgt $v0,10,print
li $v0,10
syscall

j while

print:
li $v0,1
move $a0,$v0
syscall

j while
msg1: .asciiz "This is the example of a do-while loop in MIPS assembly. "
msg2: .asciiz "Enter a number: "
.text

li $v0,4
la $a0,msg2
syscall

li $v0,5
do:
syscall
li $v0,4
la $a0,msg1
syscall

while:
bgt $v0,1,exit
j do

exit:
li $v0,10
syscall

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