The well-known Fibonacci number series, reputedly discovered by Leonardo of Pisa
ID: 3886005 • Letter: T
Question
The well-known Fibonacci number series, reputedly discovered by Leonardo of Pisa around the year 1200, has been valued for centuries for its universal qualities by artists, mathematicians, and composers. Each number in the series after the number 1 is the sum of the two previous numbers:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55 . . .
Write a program that generates and displays the first 24 numbers in the Fibonacci series, beginning with 1 and ending with 46,368.
This is my code. But the screen just shows blank space but not the integer. Can somebody help me to fix that?
title Assignment 1 (Assignment.asm)
INCLUDELIB irvine.lib
.model small
.stack 100h
.data
num dw 1
.code
extrn writeint:proc
main proc
mov ax,1
mov cx,24
start:
add ax,num
mov bx,10
call writeInt
xchg ax,num
loop start
main endp
end main
Explanation / Answer
The code below shows the fibonacci series of first 24 natural number :
.LC0:
.string "Fibonacci Series: "
.LC1:
.string "%d, "
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov DWORD PTR [rbp-16], 24
mov DWORD PTR [rbp-8], 1
mov DWORD PTR [rbp-12], 1
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
mov DWORD PTR [rbp-4], 1
.L3:
cmp DWORD PTR [rbp-4], 24
jg .L2
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov edx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-12]
add eax, edx
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-8], eax
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-12], eax
add DWORD PTR [rbp-4], 1
jmp .L3
.L2:
mov eax, 0
leave
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.