Can someone help me undestand each line of code.
I used emu8086 for this program..
Any help will be appreciated!

Title Fibonacci series
; Fibonacci series
; Write a program that generates the first 15 integers
; of the Fibonacci series {1,2,3,5,8,...}. Beginning with 
; the third element, each number is the sum of the previous 
; two numbers. Store the numbers in an array.

.model small
.stack 100h

fArray dw 15 dup(?)

main  proc

      mov    ax,@data
      mov    ds,ax

; Store the first fibonacci numbers in the array...
mov bx, offset fArray
mov dx, 0001
mov [bx], dx

; Store the first fibonacci numbers in the array...
add bx, 2
mov dx, 0002
mov [bx], dx

; Store the remaining fibonacci numbers in the array...
mov cx, 13


    ; Add the last two fibonacci numbers
    mov dx, [bx-2] 
    add dx, [bx] ; The sum of the numbers is on dx

    add bx, 2 ; increment the array index

    mov [bx], dx ; Append the new fibonacci number on the array
loop Fibonacci

;return control to DOS...
      mov    ah,4Ch 
      int    21h

main  endp
end   main

I just don't get these codes.. I tried my very best to understand these codes but I think I just lack experience on this language..
Can someone please explain these codes to me?
Thanks in advance!


    mov dx, [bx-2] 
    add dx, [bx] 

    add bx, 2 

    mov [bx], dx 
loop Fibonacci

Visualization is probably one of the best methods to comprehension. Invoke DEBUG and then step through the program one instruction at a time and just observe what's going on. OLLYBUG is even better as it lets you visualize registers memory and opcodes in a cleaner fashion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.