Question

Please Write the whole program in assembly i am able to calculate the fibonacci series but...

Please Write the whole program in assembly i am able to calculate the fibonacci series but not sure how to print it in reverse order. Please give a Complete code !!

Programming Exercise 1 (10 points): [call it Ass2-Q1.asm] Write an ASM program that reads an integer number N and then displays the first N values of the Fibonacci number sequence, described by: Fib(0) = 0, Fib(1) = 1, Fib(N) = Fib(N-2) + Fib(N-1)

Thus, if the input is N = 10, your program Ass1-Q1.exe should display the following single line:

Fibonacci sequence with N = 10 is: 55 34 21 13 8 5 3 2 1 1 0

Note: the Fibonacci sequence should be displayed in the order given above…

Homework Answers

Answer #1
.LC0:
        .string " "
reverseFibonacci(int):
        push    rbp
        mov     rbp, rsp
        push    rbx
        sub     rsp, 56
        mov     DWORD PTR [rbp-52], edi
        mov     rax, rsp
        mov     rbx, rax
        mov     eax, DWORD PTR [rbp-52]
        cdqe
        sub     rax, 1
        mov     QWORD PTR [rbp-32], rax
        mov     rdx, rax
        add     rdx, 1
        mov     r10, rdx
        mov     r11d, 0
        mov     rdx, rax
        add     rdx, 1
        mov     r8, rdx
        mov     r9d, 0
        add     rax, 1
        lea     rdx, [0+rax*4]
        mov     eax, 16
        sub     rax, 1
        add     rax, rdx
        mov     esi, 16
        mov     edx, 0
        div     rsi
        imul    rax, rax, 16
        sub     rsp, rax
        mov     rax, rsp
        add     rax, 3
        shr     rax, 2
        sal     rax, 2
        mov     QWORD PTR [rbp-40], rax
        mov     rax, QWORD PTR [rbp-40]
        mov     DWORD PTR [rax], 0
        mov     rax, QWORD PTR [rbp-40]
        mov     DWORD PTR [rax+4], 1
        mov     DWORD PTR [rbp-24], 2
.L3:
        mov     eax, DWORD PTR [rbp-24]
        cmp     eax, DWORD PTR [rbp-52]
        jge     .L2
        mov     eax, DWORD PTR [rbp-24]
        lea     edx, [rax-2]
        mov     rax, QWORD PTR [rbp-40]
        movsx   rdx, edx
        mov     ecx, DWORD PTR [rax+rdx*4]
        mov     eax, DWORD PTR [rbp-24]
        lea     edx, [rax-1]
        mov     rax, QWORD PTR [rbp-40]
        movsx   rdx, edx
        mov     eax, DWORD PTR [rax+rdx*4]
        add     ecx, eax
        mov     rax, QWORD PTR [rbp-40]
        mov     edx, DWORD PTR [rbp-24]
        movsx   rdx, edx
        mov     DWORD PTR [rax+rdx*4], ecx
        add     DWORD PTR [rbp-24], 1
        jmp     .L3
.L2:
        mov     eax, DWORD PTR [rbp-52]
        sub     eax, 1
        mov     DWORD PTR [rbp-20], eax
.L5:
        cmp     DWORD PTR [rbp-20], 0
        js      .L4
        mov     rax, QWORD PTR [rbp-40]
        mov     edx, DWORD PTR [rbp-20]
        movsx   rdx, edx
        mov     eax, DWORD PTR [rax+rdx*4]
        mov     esi, eax
        mov     edi, OFFSET FLAT:_ZSt4cout
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
        mov     esi, OFFSET FLAT:.LC0
        mov     rdi, rax
        call    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
        sub     DWORD PTR [rbp-20], 1
        jmp     .L5
.L4:
        mov     rsp, rbx
        nop
        mov     rbx, QWORD PTR [rbp-8]
        leave
        ret
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], 10
        mov     eax, DWORD PTR [rbp-4]
        mov     edi, eax
        call    reverseFibonacci(int)
        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     .L10
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L10
        mov     edi, OFFSET FLAT:_ZStL8__ioinit
        call    std::ios_base::Init::Init() [complete object constructor]
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:_ZStL8__ioinit
        mov     edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
        call    __cxa_atexit
.L10:
        nop
        leave
        ret
_GLOBAL__sub_I_reverseFibonacci(int):
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret

x86-64 gcc 10.2 compiler

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in assembly language for x86 Processors, that uses a loop to calculate the...
Write a program in assembly language for x86 Processors, that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n -1) + Fib(n - 2)
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
Write a VSC (macro) program that computes and displays a Fibonacci sequence. A Fbonacci sequence is...
Write a VSC (macro) program that computes and displays a Fibonacci sequence. A Fbonacci sequence is generated by adding the two most recent sequence numbers together, i.e., 1, 1, 1+1-2, 1+2=3, 2+3=5, 3+5=8, … The user will enter the number of terms in the sequence to be displayed. Assemble this program using the VSC assembler (ASM), and simulate this program using the VSC simulator (SIM). Include a copy of the source listing (SOURCE.DAT), the assembled listing (SLIST.DAT) and the simulation...
In Assembly x86 please Write an assembly program(call it lab6_file1.asm)that contains 10 double words in memory...
In Assembly x86 please Write an assembly program(call it lab6_file1.asm)that contains 10 double words in memory in the .data section where the first five initialized to 0 and the last five are initialized to 1. In addition, reserve ten uninitialized double words in .bss section. Using a loop, write an assembly program that copies the ten initialized values into the ten reserved double words, starting at the last position, moving to the first(reverse order the data in your uninitialized array)....
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in...
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not...
Write a .asm program that computes the Nth Fibonacci number. N will be provided in R0...
Write a .asm program that computes the Nth Fibonacci number. N will be provided in R0 and the output should be in R1
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store...
Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store the numbers in an array. The c++ program asks the user for an input to enter a positive integer 'n' and display the nth fibonacci number "FibN" that is stored inside of the array
In mathematical terms, the sequence Fn of Fibonacci numbers is 0, 1, 1, 2, 3, 5,...
In mathematical terms, the sequence Fn of Fibonacci numbers is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….. Write a function int fib(int n) that returns Fn. For example, if n = 0, then fib() should return 0, PROGRAM: C