Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code must be written for WinMIPS64. Please don\'t respond if you can\'t prov

ID: 3803869 • Letter: T

Question

The code must be written for WinMIPS64. Please don't respond if you can't provide WinMIPS64 code.

Fibonacci numbers are: 0,1,1,2,3,5,8,13,21,34,55,etc i.e. two consecutive numbers are added to generate the next number. If the user enters 6, then the display should be 0, 1, 1, 2, 3, 5 i.e. 6 fibonacci numbers should be displayed. Write the code for WinMIPS64. Generate the numbers and display it. The sample C code is:

#include

main()

{

int x,y,z,num,count;
printf( "Enter the number of fibonacci numbers > 2: ");
scanf("%d",&num);
x = 0;
y = 1;
count = 2;
printf( "The numbers are: ");
printf("%d %d ",x,y);
while(count {

z = x + y;
printf( "%d ",z);
x = y;
y = z;
count++;

}

}

Again all examples can be used for manipulation. Note that the numbers displayed are integers. Provide a complete report of your code i.e. stall count, code size, CPI.

Explanation / Answer

Answer:

Assembly Language Code:

.LC0:
        .string "Enter the number of fibonacci numbers > 2:"
.LC1:
        .string "%d"
.LC2:
        .string "The numbers are:"
.LC3:
        .string "%d %d "
.LC4:
        .string "%d "
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 32
        mov     edi, OFFSET FLAT:.LC0
        call    puts
        lea     rax, [rbp-20]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    scanf
        mov     DWORD PTR [rbp-4], 0
        mov     DWORD PTR [rbp-8], 1
        mov     DWORD PTR [rbp-12], 2
        mov     edi, OFFSET FLAT:.LC2
        call    puts
        mov     edx, DWORD PTR [rbp-8]
        mov     eax, DWORD PTR [rbp-4]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC3
        mov     eax, 0
        call    printf
.L3:
        cmp     DWORD PTR [rbp-12], 0
        je      .L2
        mov     edx, DWORD PTR [rbp-4]
        mov     eax, DWORD PTR [rbp-8]
        add     eax, edx
        mov     DWORD PTR [rbp-16], eax
        mov     eax, DWORD PTR [rbp-16]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC4
        mov     eax, 0
        call    printf
        mov     eax, DWORD PTR [rbp-8]
        mov     DWORD PTR [rbp-4], eax
        mov     eax, DWORD PTR [rbp-16]
        mov     DWORD PTR [rbp-8], eax
        add     DWORD PTR [rbp-12], 1
        jmp     .L3
.L2:
        mov     eax, 0
        leave
        ret
__static_initialization_and_destruction_0(int, int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     DWORD PTR [rbp-8], esi
        cmp     DWORD PTR [rbp-4], 1
        jne     .L7
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L7
        mov     edi, OFFSET FLAT:std::__ioinit
        call    std::ios_base::Init::Init()
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:std::__ioinit
        mov     edi, OFFSET FLAT:std::ios_base::Init::~Init()
        call    __cxa_atexit
.L7:
        nop
        leave
        ret
_GLOBAL__sub_I_main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret