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
206 Views
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
Question by:shpark82
1 Comment

LVL 22

Accepted Solution

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)
ret

ret1:
mov     #1,a
ret

0

## Featured Post

### 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…