Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fibbonacci Numbers. Solution Method: Build Table F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2)

Similar presentations


Presentation on theme: "Fibbonacci Numbers. Solution Method: Build Table F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2)"— Presentation transcript:

1 Fibbonacci Numbers

2 Solution Method: Build Table F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2) F(5) = F(4) + F(3)

3 Set Up Table to Live at 0xFFFF0100 F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2) F(5) = F(4) + F(3) 0x00001000

4 Initialize F(0) & F(1) to 1 F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2) F(5) = F(4) + F(3) Set to 1

5 Iteration Algorithm: Add F(k-2) and F(k-1) to Make F(k) F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2) F(5) = F(4) + F(3) +

6 Iteration Algorithm: Add F(k-2) and F(k-1) to Make F(k) F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2) F(5) = F(4) + F(3) +

7 Iteration Algorithm: Add F(k-2) and F(k-1) to Make F(k) F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2) F(5) = F(4) + F(3) +

8 So, … Initialize stuff to get started –Set up pointer to base of table –Put F(0), F(1) to value 1 –Establish termination condition Steady State (1): Figure out next F value –Get value pointed at (F(n-2)) –Get next value (F(n-1)) –Add and save (this is F(n))

9 And then … Steady State (2): move to next table element –Increment pointer by four Steady State (3): Check exit condition –Decrement counter –Get out if reached end of loop

10 lis r3,0xffff0100@h # set up Addr(1) ori r3,r3,0xffff0100@l # set up Addr(2) li r5,1 # constant 1 stw r5,0(r3) # set F(0) = 1 stw r5,4(r3) # set F(1) = 1 li r6,45 # get iteration num mtctr r6 # store to counter label:lwz r7,0(r3) # loop: get F(n-2) lwz r8,4(r3) # get F(n-1) add r9,r8,r7 # do the add stw r9,8(r3) # store F(n) to table addi r3,r3,4 # bump pointer bc 0x10,0,label # dec cntr & br if... nop # places for nop # breakpoints here:b here # safety? nop


Download ppt "Fibbonacci Numbers. Solution Method: Build Table F(0) F(1) F(2) F(3) F(4) F(5) F(0) = 1 F(1) = 1 F(2) = F(1) + F(0) F(3) = F(2) + F(1) F(4) = F(3) + F(2)"

Similar presentations


Ads by Google