Can someone help me undestand these codes?

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 1
Reputation: acidpaul is an unknown quantity at this point 
Solved Threads: 0
acidpaul acidpaul is offline Offline
Newbie Poster

Can someone help me undestand these codes?

 
0
  #1
Feb 29th, 2008
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

.data
fArray dw 15 dup(?)

.code
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

Fibonacci:

; 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!
=)


Fibonacci:


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

add bx, 2

mov [bx], dx
loop Fibonacci
Last edited by acidpaul; Feb 29th, 2008 at 12:23 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: Can someone help me undestand these codes?

 
0
  #2
Mar 1st, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC