Analyze the following MIPS program: helper : addi $sp,$sp,-4 sw $ra,0($sp) lw $v
ID: 644973 • Letter: A
Question
Analyze the following MIPS program:
helper :
addi $sp,$sp,-4
sw $ra,0($sp)
lw $v0, 0($ra)
lw$ra, 0($sp)
adi $sp,$sp,4
jr $ra
Mystery:
addi $sp,$sp,-8
sw $ra, 4($sp)
sw $s0,0($sp)
add $v0,$a0,$a1
jal helper
lw $s0, 0($sp)
lw $ra, 4($sp)
addi $sp, $sp, 8
jr $ra
a) What is the behavior of the helper function? Consider what is means in terms of what the value returns
b) What is the mystery equivalent in C? Don't translate it verbatim but find the most concise code in C for what it is really doing in mystery.Don't consider the behavior of helper here and use it directly if needed.
c) What does the mystery program return? Give the answer in hex and explain it
Explanation / Answer
a) helper function is used to add immediately the stack pointer with -4 and it returns 0.
b) mystery is swaping data as like in C.
c) mystery return value of $ra
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.