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

2. (10 points) Write an assembly program that takes n(where nc100) from a user a

ID: 3913392 • Letter: 2

Question

2. (10 points) Write an assembly program that takes n(where nc100) from a user and finds n Fibonacci numbers. A Fibonacci series is a series of numbers in which the next element is the sum of previous two elements. Assume that the first two elements are already initialized as follows: fibArr DWORD 0,1,98 DUP?) Example: If users gives n-S, the result should be fibArr-0, 1, 1,2,3 If user gives n-7, the result should be fibArr 0,1, 1, 2, 3, 5, 8. Hint: You would use Readint function from the Irvine32 library. O Submit the following: Lastname3.pdf

Explanation / Answer

CODE in x86-64 gcc 8.1

.LC0:

.string "Enter the number of terms: "

.LC1:

.string "%d"

.LC2:

.string "Fibonacci Series: "

.LC3:

.string "Number should be smaller than 100"

.LC4:

.string "%d, "

main:

push rbp

mov rbp, rsp

sub rsp, 32

mov DWORD PTR [rbp-8], 0

mov DWORD PTR [rbp-12], 1

mov edi, OFFSET FLAT:.LC0

mov eax, 0

call printf

lea rax, [rbp-20]

mov rsi, rax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call scanf

mov edi, OFFSET FLAT:.LC2

mov eax, 0

call printf

mov eax, DWORD PTR [rbp-20]

cmp eax, 100

jle .L2

mov edi, OFFSET FLAT:.LC3

mov eax, 0

call printf

jmp .L3

.L2:

mov DWORD PTR [rbp-4], 1

.L4:

mov eax, DWORD PTR [rbp-20]

cmp DWORD PTR [rbp-4], eax

jg .L3

mov eax, DWORD PTR [rbp-8]

mov esi, eax

mov edi, OFFSET FLAT:.LC4

mov eax, 0

call printf

mov edx, DWORD PTR [rbp-8]

mov eax, DWORD PTR [rbp-12]

add eax, edx

mov DWORD PTR [rbp-16], eax

mov eax, DWORD PTR [rbp-12]

mov DWORD PTR [rbp-8], eax

mov eax, DWORD PTR [rbp-16]

mov DWORD PTR [rbp-12], eax

add DWORD PTR [rbp-4], 1

jmp .L4

.L3:

mov eax, 0

leave

ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote