Question

please wirte the mips code main() { x = 2*foo(4*y+7); x = x+(4*y+7); } int foo...

please wirte the mips code

main() {

x = 2*foo(4*y+7);

x = x+(4*y+7);

}

int foo (int n) {

int junk[10] = {0,1,2,3,4,5,6,7,8,9};

junk[4] += 2; if (n<1)

return 1;

else

return (foo(n-1) + junk[4] + n);

}

Homework Answers

Answer #1

Greetings!!

.data
x: .word 0
y: .word 0
junk: .word 0,1,2,3,4,5,6,7,8,9
.text
#MAIN STARTS
main:
li $t0,y
sll $a0,$t0,2   #4y
addi $a0,$a0,7   #4y+7
jal foo       #FUNCTION CALL
li $v0,10
syscall
#MAIN END
#FUNCTION DEFINITION
foo:
la $t0,junk   #address of junk
li $t1,4  
li $t2,2
mul $t1,$t1,4   #calculate ofset
add $t0,$t0,$t1   #calclate index
bgt $a0,1,else   #if less than 1
sw $t2,0($t0)   #store
li $v0,1   #return value 1
jr $ra       #return
else:
lw $t3,0($t0)   #junk[4]  
move $t4,$a0   #n
addi $a0,$a0,-1 #n-1
add $a0,$t3,$t4   #n-1 + junk[4] + n
jal foo       #foo()
jr $ra       #return to main

Hope this helps

Know the answer?
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
Similar Questions
Consider the function with header: int foo(int s, int n, int a, int b). Write MIPS...
Consider the function with header: int foo(int s, int n, int a, int b). Write MIPS assembly code for the following statement located inside the above function: return(s+n);
Translate the following C code into MIPS code. int test (int n) { if (n <...
Translate the following C code into MIPS code. int test (int n) { if (n < 2 ) return (10); else { k = 20 + test (n-1); k=k + n; return (k); } } Assume variable k is assigned to register $s1. Note: your code should be complete. please dont show me the software output,
Translate C code into MIPS. Do not include an exit syscall int proc1( int a, int...
Translate C code into MIPS. Do not include an exit syscall int proc1( int a, int b ) { if ( proc2( a, b ) >= 0 ) return 1; else return -1; } int proc2( int a, int b ) { return (a*10) & (b*10); } int main() { int a = 9; int b = -10; int c = a + b + proc1( a, b ); printf("%d\n", c ); return 0; }
class Ex1{ 2. public static void main(String args[]){ 3. int x = 10; 4. int y...
class Ex1{ 2. public static void main(String args[]){ 3. int x = 10; 4. int y = new Ex1().change(x); 5. System.out.print(x+y); 6. } 7. int change(int x){ 8. x=12; 9. return x; 10. } 11. } Can you please explain this entire code and what is happening?
Below is C code and Python code for an algorithm. C code: void foo( int n,...
Below is C code and Python code for an algorithm. C code: void foo( int n, int A, int B, int C ) { if( n==1 ) { printf("%d to %d\n",A,B); return; } foo( n-1, A, C, B ); printf("%d to %d\n",A,B); foo( n-1, B, C, A ); Python code: def foo(n , A, B, C): if n==1: print A, "to", B return foo(n-1, A, C, B) print A, "to", B foo(n-1, B, C, A) Let Hn be the number...
1. Translate the following code into MIPS code. Test (int i, int j)                         {        &n
1. Translate the following code into MIPS code. Test (int i, int j)                         {                         int k;                         k = i +j +10;                         k = Sub(k+1) + Sub (k)                         return k;                         } Sub (int m)                         {                         int g;                         g = m + m;                         return g;                         } Assume variables k and g are assigned to registers $s0 and $s1, respectively. Note: your code should be complete.
A.6 ... static int x = 1; int y = x * 2; void t1() {...
A.6 ... static int x = 1; int y = x * 2; void t1() {                 y++;                 cout << "x: " << x << " | y: " << y << endl;                 y += 1;                 x -= -1; } void t2() {                 int* x = &y;                 cout << "x: " << x << " | y: " << y << endl; } void t3() {                 int y = x;                 static int x...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere else. int f2(int x, int y) { int i, z = 0; for (i = x; i <= y; i++) z = z + f1(i, 5); return z; }
public class Point { int x; int y; public Point(int initialX, int initialY){ x = initialX;...
public class Point { int x; int y; public Point(int initialX, int initialY){ x = initialX; y= initialY; } public boolean equals (Object o){ if (o instanceof Point){ Point other = (Point)o; return (x == other.x && y == other.y); }else{ return false; } } } We haev defined "equals" method for our class using "instanceof". We define and use instances (or objects) of this class in the following scenarios. In each case, specify what is the output. (hint: there...
Given the following code: int x = 0; int y = 10; int *ptr = &x;...
Given the following code: int x = 0; int y = 10; int *ptr = &x; *ptr = -55; x += -52; ptr = &y; *ptr += 52; printf("%d\n", x); What is printed to the screen?