68HC11 program that calculates f(n) which goes in sequence 1,1,2,3,5,8,13,21,34..etc

Posted on 2005-04-23
Last Modified: 2008-02-01
given f(1) = 1 and f(2) = 1  AND f(n) = f(n-1) + f(n-2)

i need a 68HC11 program that will give me the value of f(n) given n

n is given in memory location $C100, and n is positive integer

the result should be stored in accumulator A

also, the content of $C100 should not be changed.

it would be great if i could get a flow chart and the 68HC11 assembly code.

Thank you very much.
Question by:shpark82
    1 Comment
    LVL 22

    Accepted Solution

    the general idea is:

          cmp a,1
          je  ret1      ;; return 1 if arg = 1

          cmp   a,2
          je  ret1     ;; return   1 if arg  = 2

          move    a,b   ;; save for later
          dec      a
          call    func   ;; call func(n-1)
          push   a      ;; save result of functio call
          move   b,a   ;; get back parameter
           sub    #2,a   ;; n - 2 parameter
          calll    func    ;; func(n-2)
           pop    b       ;;   result from   func(n-1)
          add    b,a     ;; add them up

         mov     #1,a


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
    Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now