1 / 10

Fibbonacci Numbers

Fibbonacci Numbers. Solution Method: Build Table. F(0). F(0) = 1. F(1). F(1) = 1. F(2). F(2) = F(1) + F(0). F(3). F(3) = F(2) + F(1). F(4). F(4) = F(3) + F(2). F(5). F(5) = F(4) + F(3). Set Up Table to Live at 0xFFFF0100. F(0). F(0) = 1. F(1). F(1) = 1. F(2). F(2) = F(1) + F(0).

newton
Download Presentation

Fibbonacci Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fibbonacci Numbers

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

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

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

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

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

  7. Iteration Algorithm:Add F(k-2) and F(k-1) to Make F(k) F(0) F(0) = 1 F(1) F(1) = 1 F(2) F(2) = F(1) + F(0) F(3) F(3) = F(2) + F(1) + F(4) F(4) = F(3) + F(2) F(5) 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

More Related