Question

The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of...

  1. The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of using stack for storing/protecting registers.

  • What is the mistake and how should it be fixed? Correct the corresponding lines in the code.
  • For the corrected code, sketch the stack frame contents at the time when the instruction ‘move $s1, $a1’ is being executed.

f:   addi $sp, $sp, 12

sw   $ra, 8($sp)

sw   $s1, 4($sp)

sw   $s0, 0($sp)

move $s0, $a0

move $s1, $a1              # Stack frame?

jal g

add $v0, $v0, $s0

lw $ra, 8($sp)

lw $s1, 4($sp)

lw $s0, 0($sp)

addi $sp, $sp, -12

jr $ra

g:   mul $v0, $s0, $s1

     jr   $ra

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below shows the changed code with explanation

f:
    #Stack always grow from frame pointer to bottom
    addi $sp,$sp,-12               
    sw $ra,8($sp)
    sw $s1,4($sp)
    sw $s0,0($sp)
    #Before function call passing arguments will be a0-a3 registers
    move $a0,$s0   
    move $a1,$s1
    jal g
    add $v0,$v0,$s0
    lw $ra,8($sp)
    lw $s1,4($sp)
    lw $s0,0($sp)
    #Free the aloocated space
    addi $sp,$sp,12
    jr $ra
#Function gets parameters value from a0 and a1
#Return result from v0
g:
    mul $v0,$a0,$a1
    jr $ra         

---------------------------------------------------------

Stack frame

Add a comment
Know the answer?
Add Answer to:
The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT