Question: Hello, please answer all Q (Q1 - Q9 blanks). # EX10 - Experiment with an friendly procedure: Xfriendly # # Objective: Using Stack Operations #

Hello, please answer all Q (Q1 - Q9 blanks).

# EX10 - Experiment with an friendly procedure: Xfriendly # # Objective: Using Stack Operations # SP2021 / Coach # *** Add check point in MARS simulation to verify Stack Operation

# Simple setup: # $s0 = 1 # $s1 = 2 # $a0 = $s0 # $a1 = $s1

# call Xfriendly (inputs: $a0,$a1; output: $v0) # $s2 = $s0 + $s1 + $v0

# Expected result: $s2 = 1 + 2 + 7 = 10 = 0x0A #------------------------------------------------------------------------ main: addi $s0,$zero,0x0001 # $s0 = 1 addi $s1,$zero,0x0002 # $s0 = 2 add $a0, $zero, $s0 # set up parameter passing $a0 add $a1, $zero, $s1 # set up parameter passing $a1

jal Xfriendly # call procedure

add $t0,$s0,$s1 # $t0 = $s0 + $s1 add $s2,$t0,$v0 # $s2 = $s0 + $s1 + $v0 # MARS Simulation check point: # Q9.(1 point): after running the previous instruction: what is MARS $s2 = 0x__________________

spin_wheel: j spin_wheel # note: spinning wheel so that our baby won't get lost #====================================== Xfriendly: # Procedure Xfriendly: # take 2 inputs: $a0, $a1 # provide output at $v0 with the following criteria: # if ($a0 < $a1) then $v0 = 7 # if ($a1 >= $a1) then $v0 = 12 #=======================================

############### Stack Operation: PUSH Stack & Save $s0 to Stack ########## # MARS Simulation check point: # Q1.(1 point): before running next instruction: what is MARS $sp = 0x__________________ addi $sp, $sp, -4 # PUSH stack to save next item # MARS Simulation check point: # Q2.(1 point): after running the previous instruction: what is MARS $sp = 0x__________________ # Stack Operation check point: # Q3.(1 point): What is the difference between the values of $sp recorded in Q1 & Q2: 0x__________

sw $s0, 0($sp) # save $s0 to stack ###############################################################################

blt $a0, $a1, low high: addi $s0, $zero,12 # $s0 = 12 # just destroy original $s0 j done low: # MARS Simulation check point: # Q4.(1 point): before running the next instruction: what is MARS $s0 = 0x__________________ addi $s0, $zero,7 # $s0 = 7 # just destroy original $s0 # MARS Simulation check point: # Q5.(1 point): after running the previous instruction: what is MARS $s0 = 0x__________________ add $v0, $zero, $s0 # set up $v0 to pass result ############### Stack Operation: Restore $s0 from Stack & POP Stack ########## lw $s0, 0($sp) # restore s0 for the caller # MARS Simulation check point: # Q6.(1 point): after running the previous instruction: what is MARS $s0 = 0x__________________ addi $sp, $sp, 4 # POP stack # MARS Simulation check point: # Q7.(1 point): after running the previous instruction: what is MARS $sp = 0x__________________ # Stack Operation check point: # Q8.(1 point): What is the difference between the value of $sp in Q7 and Q1: = 0x__________________ ##################################################################################

done: jr $ra # return to caller

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!