100 likes | 205 Views
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).
E N D
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) 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)
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)
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)
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)
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)
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))
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
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