Question

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;

}

Homework Answers

Answer #1

So the code after converting into MIPS assembly language is

f2:
addiu $sp,$sp,-40
sw $31,36($sp)
sw $fp,32($sp)
move $fp,$sp
sw $4,40($fp)
sw $5,44($fp)
sw $0,28($fp)
lw $2,40($fp)
nop
sw $2,24($fp)
b $L2
nop

$L3:
li $5,5 # 0x5
lw $4,24($fp)
jal f1
nop

move $3,$2
lw $2,28($fp)
nop
addu $2,$2,$3
sw $2,28($fp)
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
$L2:
lw $3,24($fp)
lw $2,44($fp)
nop
slt $2,$2,$3
beq $2,$0,$L3
nop

lw $2,28($fp)
move $sp,$fp
lw $31,36($sp)
lw $fp,32($sp)
addiu $sp,$sp,40
j $31
nop

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
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) {...
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 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; }
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);...
In MIPS assembly, write an assembly language version of the following C code segment: int A[100],...
In MIPS assembly, write an assembly language version of the following C code segment: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }
Homework 6 Problem 2 Translate the third of the following three algorithms to C++. Write a...
Homework 6 Problem 2 Translate the third of the following three algorithms to C++. Write a program to test the function. The first few Fibonacci numbers are 1,1,2,3,5,8,13,21,34,55,89,144,… Fibonacci(n)    f1 = 0    f2 = 1    fib = 0    while n > 0      f1 = f2      f2 = fib      fib = f1 + f2      n = n – 1    end while    return fib end fibonacci fibonacci(n) if n < 1 then...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x - y[0] + y[1]; In memory x, y are stored beginning at 0x010000cc. Use registers $s1 for x,  and $s2 for the base address of y. Make sure your code includes all necessary declarations such that it could run in SPIM.
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
This question is in C++ format and relevant (a) What is the purpose of the f1...
This question is in C++ format and relevant (a) What is the purpose of the f1 function below?    int f1( int data[], int n ) {      int a = 0;      for(int i = 1; i < n; i++)            if(data[i] == 0)                 a++;      return a; } (b) In the signature of the f1 function above, state whether each of the parameters is pass-by-value or pass-by-reference? (c) Complete the definition of the function f2 below such that...
Implement the following C++ code in assembly language. Substitute calls to WriteString for the printf() function...
Implement the following C++ code in assembly language. Substitute calls to WriteString for the printf() function calls: double X; double Y; if(x<Y) printf("X is lower\n"); else printf("X is not lower\n");
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT