translate from C code to MIPS int main x Maxa b int Maxin

translate from C code to MIPS.

int main() {

    x = Max(a, b);

}

int Max(int a, int b) {

    if(a>b)

       return a;

    else

       return b;

}

Solution

.Ltext0: .globl main main: .LFB0: .cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 4883EC10 subq $16, %rsp 0008 8B55F8 movl -8(%rbp), %edx 000b 8B45F4 movl -12(%rbp), %eax 000e 89D6 movl %edx, %esi 0010 89C7 movl %eax, %edi 0012 B8000000 movl $0, %eax 00 0017 E8000000 call Max 00 001c 8945FC movl %eax, -4(%rbp) 001f B8000000 movl $0, %eax 00 0024 C9 leave .cfi_def_cfa 7, 8 0025 C3 ret .cfi_endproc .LFE0: .globl Max Max: .LFB1: .cfi_startproc 0026 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0027 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 002a 897DFC movl %edi, -4(%rbp) 002d 8975F8 movl %esi, -8(%rbp) 0030 8B45FC movl -4(%rbp), %eax 0033 3B45F8 cmpl -8(%rbp), %eax 0036 7E05 jle .L4 0038 8B45FC movl -4(%rbp), %eax 003b EB03 jmp .L5 .L4: 003d 8B45F8 movl -8(%rbp), %eax .L5: 0040 5D popq %rbp .cfi_def_cfa 7, 8 0041 C3 ret .cfi_endproc .LFE1: .Letext0:
translate from C code to MIPS. int main() { x = Max(a, b); } int Max(int a, int b) { if(a>b) return a; else return b; }Solution .Ltext0: .globl main main: .L

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site