Write a code for the calculation of the N-th Fibonacci number (for \(N > 2\)). The Fibonacci sequence is defined as follows:

$$ F(n) = F(n-1) + F(n-2) $$ for \( n > 2 \), and $$ F(0) = 0, F(1) = 1 $$

Here are the first few numbers in the Fibonacci sequence: $$ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... $$

Modify the code in such a way that it does have no hazards (the code produces correct results in the pipelined execution without the hazard unit). Minimize the number of nops in your code. Prefer instruction reordering whenever possible.

The input number 'n' is at location 'input'. Save your result to location output. Execute with pipeline with no hazard unit.

A possible solution in C

t0 = 5;  //  Set value of N
s0 = 0;  //  F(0)
s1 = 1;  //  F(1)

for(t1 = 2; t1 <= t0; t1++)
{
        t2 = s0 + s1;
        s0 = s1;
        s1 = t2;
}
Input: Data hazard prevention.
In: Size of the array located at address fibo_limit.
Out: Array of Fibonacci numbers starting at the address fibo_series.

Your program will be run with the following arguments: --dump-cycles --pipelined --hazard-unit none --cycle-limit 1000 --asm submission.S
Your program will be scored by this following metric: Runtime of the program in cycles.

For interactive solution, you can use QtRvSim. The web version of the simulator is located here.
Top Scores (cycles)
  • henjaa-3
    9
  • Tim
    9
  • melker (melsth-0)
    14
  • jdupak
    144
  • frehgl-1
    209
  • emisee-3
    256
  • sebbe
    281
  • jacras-1
    286
  • aapkii-3
    309
  • Ludado-1
    318
  • Alihel-1
    318
  • iskmat-1
    318
  • alvsta-1
    318
  • guswal-1
    318
  • aleblo-1
    318
  • jialim-3
    319
  • filekh-1
    319
  • teodur-1
    319
  • julgel-3
    319
  • joeott-1
    332
  • edvcal-1
    335
  • jolstu-10
    358
  • albinringstrom
    360
  • luiara-9
    360
  • sagand-1
    360
  • rasjac-10
    366
  • fliqli
    369
  • johase-0
    370
  • Aspirin (Aspirin_LTU_2023)
    376
  • chrbru-9
    399
  • moajoh
    441
  • mahrus
    452
  • mardyh-3
    560
  • bad_reference
    855