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…
.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
Get Answers For Free
Most questions answered within 1 hours.