Skip to main content

Fibonacci single-purpose processor

Short answer

The processor initializes a=0, b=1, then loops outputting a, computing next = a+b, updating a=b, b=next until count=n. The FSMD has states wait, test, output, update. Datapath includes registers A, B, T, I, an adder for next, incrementer for count, and comparator; controller sequences loads and outputs.

Design a single-purpose processor that outputs Fibonacci numbers up to 'n' places. Start with a function computing the desired result, translate it into a state diagram and sketch a probable datapath.

Assumption: the processor takes an input n and outputs the first n Fibonacci numbers (0, 1, 1, 2, 3, 5, ...), one per output, with a start input and a done output.

Step 1: Function (algorithm)

 Fibonacci(n):
   a = 0; b = 1; i = 0
   while (i < n) {
       output a
       t = a + b
       a = b
       b = t
       i = i + 1
   }

Step 2: State diagram (FSMD)

   start=0 (loop)
      +---+
      v   |    start=1
    +----------+ a=0,b=1,i=0  +---------+
    | S0 wait  |------------->| S1 test |
    +----------+              +---------+
      ^                     i<n |   | i>=n
      |                         v   v
      |  done=1  +--------+  +----+ +------+
      +----------| S4 done|  | S2 |  (to S4)
                 +--------+  |out=a, t=a+b|
                             +-----+------+
                                   v
                             +-----------+
                             | S3 a=b    |
                             | b=t,i=i+1 |--> S1
                             +-----------+

Simplified state table:

StateConditionActionsNext
S0 (wait)start = 0done = 0S0
S0start = 1a = 0, b = 1, i = 0S1
S1 (test)i < nnoneS2
S1i >= ndone = 1S4
S2 (output)alwaysout = a, valid = 1, t = a + bS3
S3 (update)alwaysa = b, b = t, i = i + 1S1
S4 (finish)alwaysdone = 1S0

Step 3: Probable datapath

        n --------------------+
                              v
  +---+   +---+   +---+    +------+  i<n (status)
  | A |   | B |   | T |    |  <   |-----------> to controller
  +-+-+   +-+-+   +-+-+    +--^---+
    |  \    |  /    ^         |
    |   +-->[ + ]----+       +-+-+
    |       adder           | I |<-[+1]
    v                       +---+
  out (a)

Components: registers A, B, T (data) and I (counter), an adder (a + b), an incrementer (i + 1), a comparator (i < n), muxes in front of A (0 or B) and B (1 or T) and output register. Control signals from the controller: load/clear A, B, T, I; mux selects; output enable. Status to controller: i < n.

Controller

A 5-state FSM (3 flip-flops, binary encoded) that generates the loads shown in the table and receives start and i<n. Example n = 5 outputs 0, 1, 1, 2, 3.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 2 questions →