



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




All the work is my own. I had no prior knowledge of the exam contents nor will I share the contents with others
Problem 0 1 2 3 4 5 6 7 8 9 Total Min 2 8 20 30 30 30 15 1 14 150 Max 0/- 1 2 4 8 16 14 18 6 3 4 75 Score
int replaceInt(int array, int toReplace, int replaceWith) { for(;array; array++) { if(array == toReplace) { array[0] = replaceWith; return array; } } return NULL; } line 0 # replaceInt: ___ ___ ___(____)
1 beq ___ ___ endLoop # We’re done 2 beq ___ ___ doReplace # Let’s replace it 3 addiu ___ $a0 ___ # _______________________ 4 j ________________ 5 doReplace: ____ ___ ___(____) # _______________________ 6 ____ ___ ___ # _______________________ 7 j ret 8 endLoop: move ___ ___ # return NULL 9 ret: jr $ra
replaceInt(myArray, 1, 2)
Move line __ to __ (and change ______________________________________________________) Move line __ to __ (and change ______________________________________________________) Move line __ to __ (and change ______________________________________________________) Delete line __
1 mystery: bnez $a0, recur # int mystery(int n) { 2 li $v0, 0 # 3 jr $ra # 4 recur: sub $sp, $sp, 8 # 5 sw $ra, 4($sp) # 6 sub $a0, $a0, 1 # 7 jal mystery # 8 sw $v0, 0($sp) # 9 jal mystery # 10 lw $t0, 0($sp) # 11 addu $v0, $v0, $t0 # 12 addu $v0, $v0, 1 # 13 add $a0, $a0, 1 # 14 lw $ra, 4($sp) # 15 add $sp, $sp, 8 # 16 jr $ra #