I have to convert the following C function to MIPS:
int my_function(int x, int y)
{
 int i,a;
 a = x+y;
 i = x-2;
 a = a+i;
 return a;
}
Assume that the variables x and y are passed from argument registers $a0 and $a1 respectively. The returned value should be stored in register $v0. Note that you need to use stack to store any other registers if you use them in this procedure.
Since I am new to MIPS I tried referring to a C to MIPS online convertor and I got this result:
my_function(int, int):
    push    rbp
    mov     rbp, rsp
    mov     DWORD PTR [rbp-20], edi
    mov     DWORD PTR [rbp-24], esi
    mov     edx, DWORD PTR [rbp-20]
    mov     eax, DWORD PTR [rbp-24]
    add     eax, edx
    mov     DWORD PTR [rbp-4], eax
    mov     eax, DWORD PTR [rbp-20]
    sub     eax, 2
    mov     DWORD PTR [rbp-8], eax
    mov     eax, DWORD PTR [rbp-8]
    add     DWORD PTR [rbp-4], eax
    mov     eax, DWORD PTR [rbp-4]
    pop     rbp
    ret
Can I get a better solution for this?
 
     
    