Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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
1
Medium Priority
?
208 Views
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.
0
Comment
Question by:shpark82
1 Comment
 
LVL 22

Accepted Solution

by:
grg99 earned 1500 total points
ID: 13853658
the general idea is:

func:
      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
       ret


ret1:
     mov     #1,a
     ret

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Machine Learning is one of the profound applications of AI and therefore, just like AI, it is surrounded by myths and fears. Check out these facts about ML that demystify the related myths.
Conducting a customer service survey used to be as straightforward as sending a template email out using checkboxes and numerical rating systems to measure satisfaction.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

578 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