Answered step by step
Verified Expert Solution
Link Copied!

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

C/C++ 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 =2*foo(4*y+4);
x = x+(4*y+4);
{
int foo(int n)
{
int magic[12];//Mod1-assumemagicisstoredabove(i.e., loweraddress
junk on stack
int junk[10]={0,1,2,3,4,5,6,7,8,9};
junk[4]+=2-magic[5];//Mod2
if(n<1)return1;
elsereturn2*bar(n,magic[5],n,n,magic[5])+junk[4]+foo(n-1);//Mod3
}
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->$s0, y->$s1
# Assume optimizing compiler avoids computing 4*y+4 twice
Main: add $t0,$s1,$s1 # $t02y
add $t0,$t0,$t0 # $t04y
addi $t0,$t0,4 # $t04y+4
addi $sp,$sp,-4 # Push $t0
sw $t0,0($sp)
add $a0,$t0,$zero # arg04y+4
jal Foo # Call foo
lw $t0,0($sp ) # Pop $t0
addi $sp,$sp,4 #
add $s0,$v0,$v0 # x 2*foo(4*y+4)
add $s0,$t0,$s0 # x x+4*y+4
... # End of Main
Foo: addi $sp,$sp,-48 # Push:
sw $ra,44($sp) # $ra
sw $fp,40($sp) # $fp
addi $fp,$sp,44 # Set $fp to point to frame
add $t1,$zero,$zero # $t10
sw $t1,-44($fp) # junk[0]0
addi $t1,$t1,1 # $t11
sw $t1,-40($fp) # junk[1]1
...
addi $t1,$t1,9 # $t19
sw $t1,-8($fp) # junk[9]9
lw $t1,-28($fp) # $t1 junk[4]
addi $t1,$t1,2 # $t1 junk[4]+2
sw $t1,-28($fp) # junk[4] junk[4]+2
slti $t0,$a0,1 # $t01 if n<1; else 0
bne $t0,$zero,RetOne # Return 1 if n<1
# Call foo(n-1)
addi $sp,$sp,-4 # Push
sw $a0,0($sp) # ... $a0
addi $a0,$a0,-1 # arg0 n-1
jal Foo # Call foo(n-1)
lw $a0,0($sp) # Pop $a0
addi $sp,$sp,4
lw $t1,-28($fp) # $t1 junk[4]
add $v0,$v0,$t1 # $v0 foo(n-1)+junk[4]
j Ret # Return
RetOne: addi $v0,$zero,1 # $v01
Ret: lw $fp,40($sp) # pop $fp
lw $ra,44($sp) # pop $ra
addi $sp,$sp,48 # 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago