Question

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,

Homework Answers

Answer #1

MIPS Code:

    .file       1
        .previous
        .text
        .align  2
        .globl  test
        .ent    test
        .type   test, @function
test:
        .frame  $sp,0,$31
        move    $2,$0
$L3:
        slt     $3,$4,2
        bne     $3,$0,$L2
        addiu   $4,$4,-1

        addiu   $3,$4,21
        b       $L3
        addu    $2,$2,$3

$L2:
        j       $31
        addiu   $2,$2,10

        .end    test
        .size   test, .-test

Thank You!

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
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; }
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i >...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i > 10) MemArray[i] = 0; else MemArray[i] = - MemArray[i]; Assume that the variable i is bound to register $t0, and that the base address of array MemArray is in register $s0.
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; }
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); }
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed...
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed starting at location 8000. Create labels for branch and jump instructions and indicate the 0001 0001 0010 1000 0000 0000 0000 0011 1000 1110 0001 0001 0000 0000 0000 1000 0010 0010 0010 1000 0000 0000 0000 0110 0000 1000 0000 0000 0000 0001 0000 0010 b. Translate the following C function into MIPS assembly code. int f1(int ar1[], int ar2[], int n) {...
Define a recurrence F(n) for the code: int a(int i, int j){ if( j <= 1)...
Define a recurrence F(n) for the code: int a(int i, int j){ if( j <= 1) return i+20; else return j + a(i+10, j-3); } This recurrence I've come up with is F(n) = 2 if j <= 1 and F(n) = 2 + F(i+10, j-3). Now I need to solve this recurrence and represent it in big O notation which I'm unsure how to do. The main thing throwing me off is that there are two variables in the...
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include...
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include <stdlib.h> double fact (double); void main () { int angle_in_D; double term, angle_in_R; float sine = 0; unsigned int i = 1; double sign = 1; int n = 1000; printf ("Please enter an angle (Unit: Degree): "); scanf ("%d", &angle_in_D); angle_in_R = angle_in_D * M_PI / 180.0; do { term = pow(-1,(i-1)) * pow (angle_in_R, (2*i - 1)) / fact (2*i - 1);...
Given the following function:      int C(int n, int k)                  {              
Given the following function:      int C(int n, int k)                  {                     if (k= =0) return 1;                        else return (C(n-1, k-1) * n)/k;                                       } What type of function is this? Recursive or Iterative. Explain your answer.
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...
What will be the output of the following C code segment? int u = 0x2; int...
What will be the output of the following C code segment? int u = 0x2; int v = 0x35; if (u && v) printf(“Great!! \n”); else printf(“Fantastic!! \n”);
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT