Please help with this MIPS assembly language question Consid
Please help with this MIPS assembly language question!
Consider a code fragment of the non-leaf function named _foo below: _foo: addi $sp, $sp, -12 sw $ra, 0($sp) sw $s0, 4($sp) sw $sl, 8($sp) sw $s2, 12($sp):: 1w $s2, 12 ($sp) 1w $s1, 8 ($sp) 1w $s0, 4 ($sp) 1w $ra, 0 ($sp) addi $sp, $sp, 12 jr $ra Is there any wrong with the above code fragment? a. This function does not need to backup $ra. The first line should be addi $sp, $sp, 12 and the second to last line should be addi $sp, $sp, -12 The activation frame is too small. Nothing wrong with the above code fragment.Solution
Yes, the code given above has a wrong fragment which is
a. This function does not need to backup $ra.
This is because in the above code register $ra contains the return address in the caller function, registers $sp and $s3 have the same values they had when function f was called, and register $t5 can have
an arbitrary value. For $t5, although our function f does not modify it, function func is allowed to modify it so we cannot assume anything about $t5 after function func has been called.
