public static void mainString args int a new int20 a0 0

public static void main(String [] args)

    {

        int[] a = new int[20];

        a[0] = 0;

        a[1] = 1;

        for(int i = 2; i < 20; i++){

            a[i] = a[i - 1] + a[i - 2];

        }

        for(int i = 0; i < a.length; i++)

            System.out.println(a[i]);

    }

what is this code in MIPs?Convert Java into MIPs code.

Solution

MIPS CODE:

main:
.LFB0:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $112, %rsp
   movq   %fs:40, %rax
   movq   %rax, -8(%rbp)
   xorl   %eax, %eax
   movl   $0, -96(%rbp)
   movl   $1, -92(%rbp)
   movl   $2, -100(%rbp)
   jmp   .L2
.L3:
   movl   -100(%rbp), %eax
   subl   $1, %eax
   cltq
   movl   -96(%rbp,%rax,4), %edx
   movl   -100(%rbp), %eax
   subl   $2, %eax
   cltq
   movl   -96(%rbp,%rax,4), %eax
   addl   %eax, %edx
   movl   -100(%rbp), %eax
   cltq
   movl   %edx, -96(%rbp,%rax,4)
   addl   $1, -100(%rbp)
.L2:
   cmpl   $19, -100(%rbp)
   jle   .L3
   movl   $0, -100(%rbp)
   jmp   .L4
.L5:
   movl   -100(%rbp), %eax
   cltq
   movl   -96(%rbp,%rax,4), %eax
   movl   %eax, %esi
   movl   $.LC0, %edi
   movl   $0, %eax
   call   printf
   addl   $1, -100(%rbp)
.L4:
   cmpl   $19, -100(%rbp)
   jle   .L5
   movl   $0, %eax
   movq   -8(%rbp), %rcx
   xorq   %fs:40, %rcx
   je   .L7
   call   __stack_chk_fail
.L7:
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc

public static void main(String [] args) { int[] a = new int[20]; a[0] = 0; a[1] = 1; for(int i = 2; i < 20; i++){ a[i] = a[i - 1] + a[i - 2]; } for(int i = 0
public static void main(String [] args) { int[] a = new int[20]; a[0] = 0; a[1] = 1; for(int i = 2; i < 20; i++){ a[i] = a[i - 1] + a[i - 2]; } for(int i = 0

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site