-1

I have 2 functions in c that I would like to see what they would look like in mips and this is because I need some examples to study and use for reference because I am a beginner in mips. I am also using qtspim.

Recursive function:

int my_fib(int n){
    if (n==0)
        return 2;
    else if (n==1)
        return 3;
    else 
        return my_fib(n-1)+my_fib(n-2);
}

A function with a pointer:

int set(int a[], int n, int v)
{
    int i;
    for (i=n-1; i >= 0; i--) {
        a[i] = v;
    } 
    return i;
}

I would be very thankful if anyone could convert these to mips and give me an explanation of each step so I can get an idea on how to do other functions like these.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

You can try this pdf from the University of Maryland to learn the step by step techniques for C to MIPS conversion. This helped me a lot too.

After you have mastered the techniques pretty well, try this site to evaluate yourself. Check this image

Hope it helps!

TrojanMe
  • 1
  • 1
0

This is what I have so far

.text
.globl main

set:

        li $t1, 1
        li $s0, 4
        addi $t0, $a1, -1
Loop:   slt $t2, $t1, $t0
        beq $t2, $t1, End
        addi $t0, $t0, -1
        sw $s0, $a0($t0)
        j Loop
End:
        add $ra, $0, $t0
        jal $ra