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)

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Branches Two branch instructions:
The University of Adelaide, School of Computer Science
CDA 3100 Recitation Week 8. Question 1.data A:.word 21,3,2,9,100,22,6,15,33,90.text.globl main main: la $a0, A li $a1, 17 li $a2, 10 jal funct li $v0,
Lecture 6 Programming the TMS320C6x Family of DSPs.
Chapter 7 Introduction to LC-3 Assembly Language Assembly Language Assembly Process Using the Editor & Simulator for Assembly Language Programming.
Assembly Code Example Selection Sort.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
The University of Adelaide, School of Computer Science
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
08 Deterministic iteration1May Deterministic iteration CE : Fundamental Programming Techniques.
P449. p450 Figure 15-1 p451 Figure 15-2 p453 Figure 15-2a p453.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
Overview Program in LC-3 machine language Use the Editor
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.
Chapters 9 & 10 Midterm next Wednesday (11/19) Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET The Stack SSP & USP Interrupts RTI.
Introduction to LC-3 Assembly Language
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
1 CS Programming Languages Random Access Machines Jeremy R. Johnson.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
CHAPTER 2 ISA Instructions (logical + procedure call)
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Logic Structure - focus on looping Please use speaker notes for additional information!
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
Lecture 15 Today’s lecture MARIE programming Assembler
CPS120 Introduction to Computer Programming The Programming Process.
Character Data and 32-bit Constants (Lecture #20) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Repetition Control Structures Simple Program Design Third Edition A Step-by-Step Approach 5.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
Repetition loops Is a condition true? START END OF LOOP EXIT.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
CS320n – Elements of Visual Programming Assignment Help Session.
Indexed Addressing addition to implementing new instructions, the extended assembler implements a new addressing mode. This is indexed addressing, a mode.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Memory Management Damian Gordon.
Chapter 6 Programming Adapted from slides provided by McGraw-Hill Companies Inc., modified by professors at University of Wisconsin-Madison.
Presentation on Real Mode Memory Addressing
Department of Computer Science
JavaScript: Control Statements.
Computer Science 101 While Statement.
Chapter 13 Control Structures
Arrays, For loop While loop Do while loop
CS203 – Advanced Computer Architecture
Chapter 13 Control Structures
Systems Architecture I (CS ) Lecture 1: Random Access Machines
Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)
Dijkstra’s Algorithm Run by hand Dijkstra's Algorithm (as stated in slide 68 at on the example.
The University of Adelaide, School of Computer Science
Lecture: Static ILP Topics: loop unrolling, software pipelines (Sections C.5, 3.2)
Iteration: Beyond the Basic PERFORM
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
MIPS coding.
Chapter 7 Assembly Language
Algorithms computer as the tool process – algorithm
Review.
Problem: Consider the following two SRC code segments for implementing multiplication. Find which one is more efficient in terms of instruction count and.
CS100A Sections Dec Loop Invariant Review C Review and Example
Systems Architecture I (CS ) Lecture 1: Random Access Machines
MIPS function continued
Presentation transcript:

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) F(5) = F(4) + F(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) 0x

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

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

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

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

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 # set up Addr(1) ori # 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