translate from C code to MIPS code example like this max lw

translate from C code to MIPS code.

example like this:

max:
lw $t0, ($a)
lw $t1, ($b)
bgt $t0, $t1, then
jr $t1
then:
jr $t0

int main() {

    x = Max(a, b);

}

int Max(int a, int b) {

    if(a>b)

       return a;

    else

       return b;

}

Solution

Answer:

MIPS Assembly Language Code :

main:
push rbp
mov rbp, rsp
sub rsp, 16
mov edx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-4]
mov esi, edx
mov edi, eax
call max(int, int)
mov DWORD PTR [rbp-12], eax
mov eax, 0
leave
ret

push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-8]
jle .L4
mov eax, DWORD PTR [rbp-4]
jmp .L5
.L4:
mov eax, DWORD PTR [rbp-8]
.L5:
pop rbp
ret

translate from C code to MIPS code. example like this: max: lw $t0, ($a) lw $t1, ($b) bgt $t0, $t1, then jr $t1 then: jr $t0 int main() { x = Max(a, b); } int M
translate from C code to MIPS code. example like this: max: lw $t0, ($a) lw $t1, ($b) bgt $t0, $t1, then jr $t1 then: jr $t0 int main() { x = Max(a, b); } int M

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site