Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C / C + + to Mips don't change the code just modify it according to the instructions, and give me whole code with proper
CC to Mips
don't change the code just modify it according to the instructions, and give me whole code with proper comments don't use ai please, or copy other answer
main
x fooy;
x xy;
int fooint n
int magic;Modassumemagicisstoredaboveie loweraddress
junk on stack
int junk;
junkmagic;Mod
ifnreturn;
elsereturnbarnmagicnnmagicjunkfoon;Mod
Modify the following assembly language for this revised program. You may assume that bar is an OS function that has already been written. Of course, you have to use the procedure convention described in class. In cases where the convention was left unspecified, use the convention of the example. Also note that we need to call bar before foo as in the HLL code, since the compiler doesnt know whether bar has side effects such as unadvisedly playing with pointers to modify a variable in foo. Make sure to use a different ink color or boldface font to make your modifications clear, and label your program to indicate which changes support which mod. DO NOT change the original code, except as needed for these modifiations.
Thank you.
The assembly code I gave
in class or a slight variation is below:
# Allocate Registers:
x$s y$s
# Assume optimizing compiler avoids computing y twice
Main: add $t$s$s # $ty
add $t$t$t # $ty
addi $t$t # $ty
addi $sp$sp # Push $t
sw $t$sp
add $a$t$zero # argy
jal Foo # Call foo
lw $t$sp # Pop $t
addi $sp$sp #
add $s$v$v # x fooy
add $s$t$s # x xy
# End of Main
Foo: addi $sp$sp # Push:
sw $ra$sp # $ra
sw $fp$sp # $fp
addi $fp$sp # Set $fp to point to frame
add $t$zero,$zero # $t
sw $t$fp # junk
addi $t$t # $t
sw $t$fp # junk
addi $t$t # $t
sw $t$fp # junk
lw $t$fp # $t junk
addi $t$t # $t junk
sw $t$fp # junk junk
slti $t$a # $t if n; else
bne $t$zero,RetOne # Return if n
# Call foon
addi $sp$sp # Push
sw $a$sp # $a
addi $a$a # arg n
jal Foo # Call foon
lw $a$sp # Pop $a
addi $sp$sp
lw $t$fp # $t junk
add $v$v$t # $v foonjunk
j Ret # Return
RetOne: addi $v$zero, # $v
Ret: lw $fp$sp # pop $fp
lw $ra$sp # pop $ra
addi $sp$sp # reclaim stack space
jr $ra # return to call
This is the procedure convention
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started