Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Fabonacci Numbers

erldeeerldee Member Posts: 19
[b][red]This message was edited by erldee at 2002-8-21 4:18:27[/red][/b][hr]
Hi

any one who is having idea of how to write a assembly program that generate first 24 numbers of Fabonacci(each number in the series after one is the sum of the two previous numbers).

e.g. 1,1,2,3,5,8,13,21...


Comments

  • Josh CodeJosh Code Member Posts: 675
    : [b][red]This message was edited by erldee at 2002-8-21 4:18:27[/red][/b][hr]
    : Hi
    :
    : any one who is having idea of how to write a assembly program that generate first 24 numbers of Fabonacci(each number in the series after one is the sum of the two previous numbers).
    :
    : e.g. 1,1,2,3,5,8,13,21...
    :
    :
    :

    I'm not experienced with assembly but I'll give you some code that should help with the calculations. This code is from Delphi. As you can see it is mostly built-in assembly code, however.

    [code]
    [b]function[/b] fib2(i: integer): integer;
    [b]var[/b]
    v,n,n1,n2: integer;
    [b]begin[/b]
    [b]asm[/b]
    mov n,0; mov n1,1; mov n2,1;
    [b]end;[/b]
    [b]for[/b] v:=1 [b]to[/b] i [b]do[/b] // in c++, for (v=1;v<i;v++)
    [b]begin
    asm[/b]
    mov eax,n1; add eax,n; mov n2,eax;
    mov eax,n1; mov n,eax;
    mov eax,n2; mov n1,eax;
    [b]end;
    end;
    asm[/b]
    mov eax,n2;mov result,eax; // store the result
    [b]end;
    end;[/b][/code]

    // fib2(1) = 1, fib2(2) = 2, fib2(3) = 3, fib2(4) = 5, fib2(5) = 8...
  • blipblip Member Posts: 756
    [b][red]This message was edited by blip at 2002-10-18 15:55:49[/red][/b][hr]
    Here's the core code (just a little procedure), I'll leave the rest to you as a challenge:
    [code]
    Fibonacci:
    ;Input: AX and BX = Two of the numbers of the sequence
    ;Output: AX and BX = Next two numbers in the sequence
    ;Destroyed: CX and DX (actually CX=AX and DX=BX)
    mov cx,ax
    add cx,bx
    mov dx,bx
    add dx,cx
    mov ax,cx
    mov bx,dx
    ret
    [/code]

    Don't forget to look in older posts for a decimal display procedure if you don't have one already.


  • Andre YoungAndre Young USAMember Posts: 0

    _ || http://forcoder.org || free video tutorials and ebooks about { C# Delphi Ruby PHP Visual Basic .NET Java MATLAB Perl Visual Basic PL/SQL Objective-C C++ Python JavaScript Swift Assembly R C Go Scratch Kotlin Rust F# ML ABAP Scheme VBScript Crystal Bash Logo D Erlang Clojure Julia Awk SAS Dart Lisp Fortran Apex Lua LabVIEW Alice Hack Scala COBOL Prolog FoxPro Ada Transact-SQL } ____

Sign In or Register to comment.