Fibonacci

just started assembler language at home..
Could anyone send me code for the following...

.data
list dw 1,2,13 dup(0)

I need to add the first two numbers and put the result into the following position throughout the loop

output should be 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

thanks tekis

Comments

  • : just started assembler language at home..
    : Could anyone send me code for the following...
    :
    : .data
    : list dw 1,2,13 dup(0)
    :
    : I need to add the first two numbers and put the result into the following position throughout the loop
    :
    : output should be 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
    :
    : thanks tekis
    :

    [green]
    No need to send you the code because I'll do it for ya alright.

    [code]
    ;USE NASM

    org 0x100

    mov ax, 3
    int 10h

    mov ah, 9
    mov dx, offset output
    int 21h

    mov ah, 0
    int 16h

    mov ax, 4c00h
    int 21h

    output db 68,79,0,89,79,85,82,0,79,87,78,0,72,79,77,69,87,79,82,75,'$'
    [/code]
    [/green]

  • : : just started assembler language at home..
    : : Could anyone send me code for the following...
    : :
    : : .data
    : : list dw 1,2,13 dup(0)
    : :
    : : I need to add the first two numbers and put the result into the following position throughout the loop
    : :
    : : output should be 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
    : :
    : : thanks tekis
    : :
    :
    : [green]
    : No need to send you the code because I'll do it for ya alright.
    :
    : [code]
    : ;USE NASM
    :
    : org 0x100
    :
    : mov ax, 3
    : int 10h
    :
    : mov ah, 9
    : mov dx, offset output
    : int 21h
    :
    : mov ah, 0
    : int 16h
    :
    : mov ax, 4c00h
    : int 21h
    :
    : output db 68,79,0,89,79,85,82,0,79,87,78,0,72,79,77,69,87,79,82,75,'$'
    : [/code]
    : [/green]
    :
    :
    Hey I like that piece of code!
    ;-)

  • : just started assembler language at home..
    : Could anyone send me code for the following...
    :
    : .data
    : list dw 1,2,13 dup(0)
    :
    : I need to add the first two numbers and put the result into the following position throughout the loop
    :
    : output should be 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
    :
    : thanks tekis
    :

    Here is the HLA version:

    [CODE]program DemoRecursion;
    #include( "stdlib.hhf" );

    var
    myfib:int32;


    /*
    ** Compute fibonocci sequence (digusting, slow, way )
    ** using a recursive call.
    */

    procedure fib( n:int32 ); @nodisplay;
    begin fib;

    if( n <= 2 ) then

    mov( 1, eax );

    else

    mov( n, eax ); // Compute fib( n-1 );
    dec( eax );
    fib( eax );
    push( eax ); // Save result of fib(n-1);

    mov( n, eax ); // Compute fib( n-2 );
    sub( 2, eax );
    fib( eax );
    add( [esp], eax ); // Add fib(n-1) and fib(n-2)
    add( 4, esp ); // Clean up stack.

    endif;

    end fib;

    begin DemoRecursion;

    mov( 0, myfib );
    while( myfib < 10 ) do

    fib( myfib );
    stdout.put( "fib(", myfib, ") = ", (type int32 eax ), nl );
    inc( myfib );

    endwhile;

    end DemoRecursion;[/CODE]

    This was found in the HLA Examples/Sample Code download at:
    http://webster.cs.ucr.edu/AsmTools/HLA/dnld.html


  • actually if you want the fibonacci sequence it is 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

Sign In or Register to comment.

Howdy, Stranger!

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

Categories