Skip to content

Commit 1d3532f

Browse files
committed
fibonaci on demo with updated memorh
1 parent bac447f commit 1d3532f

File tree

6 files changed

+5091
-359
lines changed

6 files changed

+5091
-359
lines changed

demo/index.html

Lines changed: 80 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<meta name="description" content="Interactive visualization of RISC-V CPU implementations, including sequential and pipelined architectures." />
7-
<meta name="keywords" content="RISC-V, CPU, Visualization, Sequential, Pipelined, Processor, Simulation" />
6+
<meta
7+
name="description"
8+
content="Interactive visualization of RISC-V CPU implementations, including sequential and pipelined architectures."
9+
/>
10+
<meta
11+
name="keywords"
12+
content="RISC-V, CPU, Visualization, Sequential, Pipelined, Processor, Simulation"
13+
/>
814
<meta name="author" content="MostlyKIGuess" />
9-
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
15+
<link
16+
href="https://fonts.googleapis.com/icon?family=Material+Icons"
17+
rel="stylesheet"
18+
/>
1019
<title>RISC-V CPU Visualizer</title>
1120
<link rel="icon" type="image/jpg" href="./catprocessor.jpg" />
1221
<link rel="stylesheet" href="css/styles.css" />
@@ -15,9 +24,13 @@
1524
<div class="container">
1625
<div class="header-container">
1726
<h1>RISC-V CPU Visualization</h1>
18-
27+
1928
<div class="top-links">
20-
<a href="https://github.com/MostlyKIGuess/RISC-V-Processor-Implementation/" class="github-link" target="_blank">
29+
<a
30+
href="https://github.com/MostlyKIGuess/RISC-V-Processor-Implementation/"
31+
class="github-link"
32+
target="_blank"
33+
>
2134
<span class="icon">&#xe043;</span> GitHub Repository
2235
</a>
2336
<a href="./report/Report.pdf" class="report-link" download>
@@ -94,7 +107,9 @@ <h2>Sequential CPU</h2>
94107
</ul>
95108

96109
<div class="button-container">
97-
<a href="sequential/index.html" class="button">Launch Sequential CPU</a>
110+
<a href="sequential/index.html" class="button"
111+
>Launch Sequential CPU</a
112+
>
98113
</div>
99114
</div>
100115

@@ -113,7 +128,9 @@ <h2>Pipelined CPU</h2>
113128
</ul>
114129

115130
<div class="button-container">
116-
<a href="pipelined/index.html" class="button">Launch Pipelined CPU</a>
131+
<a href="pipelined/index.html" class="button"
132+
>Launch Pipelined CPU</a
133+
>
117134
</div>
118135
</div>
119136
</div>
@@ -123,9 +140,7 @@ <h2>Demo Programs</h2>
123140

124141
<div class="program-container">
125142
<h3>Sequential CPU Program</h3>
126-
<p>
127-
The Sequential CPU demo executes the following RISC-V program:
128-
</p>
143+
<p>The Sequential CPU demo executes the following RISC-V program:</p>
129144
<div class="demo-code">
130145
<pre><code>addi x1, x0, 15 # Initialize x1 = 15
131146
addi x2, x0, 25 # Initialize x2 = 25
@@ -169,24 +184,24 @@ <h4>Program Explanation:</h4>
169184
</p>
170185
<ol>
171186
<li>
172-
<strong>Register Initialization</strong>: Sets initial values
173-
in registers x1-x4 using immediate values
187+
<strong>Register Initialization</strong>: Sets initial values in
188+
registers x1-x4 using immediate values
174189
</li>
175190
<li>
176191
<strong>Arithmetic Operations</strong>: Performs addition and
177192
subtraction between registers
178193
</li>
179194
<li>
180-
<strong>Logical Operations</strong>: Performs bitwise AND and
181-
OR operations
195+
<strong>Logical Operations</strong>: Performs bitwise AND and OR
196+
operations
182197
</li>
183198
<li>
184199
<strong>Memory Operations</strong>: Stores and loads values
185200
to/from memory
186201
</li>
187202
<li>
188-
<strong>Branching</strong>: Uses conditional branches to
189-
control program flow
203+
<strong>Branching</strong>: Uses conditional branches to control
204+
program flow
190205
</li>
191206
<li>
192207
<strong>Control Flow</strong>: Demonstrates label-based
@@ -205,54 +220,65 @@ <h4>Program Explanation:</h4>
205220
<h3>Pipelined CPU Program</h3>
206221
<p>The Pipelined CPU demo executes the following RISC-V program:</p>
207222
<div class="demo-code">
208-
<pre><code>begin:
209-
addi x1, x0, 3 # x1 = 3
210-
addi x2, x0, 7 # x2 = 7
211-
212-
loop:
213-
beq x1, x0, exit # if x1==0, end program
214-
add x2, x2, x1 # x2 = x1 + x2
215-
addi x1, x1, -1 # x1--
216-
beq x0, x0, loop # loop
217-
218-
exit:
219-
nop # No operation</code></pre>
223+
<pre><code>start:
224+
ld x1, 0(x0) # Load n from memory
225+
addi x2, x0, 0 # x2 = 0 (Fib(0))
226+
addi x3, x0, 1 # x3 = 1 (Fib(1))
227+
beq x1, x0, done # If n == 0, return Fib(0)
228+
addi x1, x1, -1 # Decrement n by 1 to account for Fib(1)
229+
beq x1, x0, done1 # If n == 1, return Fib(1)
230+
231+
loop:
232+
add x4, x2, x3 # x4 = x2 + x3 (Fib(n) = Fib(n-1) + Fib(n-2))
233+
add x2, x3, x0 # x2 = x3 (shift Fib(n-1) to Fib(n-2))
234+
add x3, x4, x0 # x3 = x4 (shift Fib(n) to Fib(n-1))
235+
addi x1, x1, -1 # Decrement n
236+
beq x1, x0, done1 # Repeat until n == 0
237+
beq x0, x0, loop
238+
239+
done1:
240+
add x4, x3, x0 # Return Fib(1)
241+
242+
done:
243+
# x4 holds the Fibonacci result
244+
addi x0, x0, 0
245+
nop</code></pre>
220246
</div>
221247
<div class="program-explanation">
222248
<h4>Program Explanation:</h4>
223249
<p>
224-
This program is specifically designed to demonstrate pipeline
225-
hazards and their resolution:
250+
This Fibonacci calculator demonstrates pipeline hazards and their
251+
resolution:
226252
</p>
227253
<ol>
228254
<li>
229255
<strong>Data Hazards</strong>: The program creates register
230-
dependencies between instructions (x1 and x2 are both read and
231-
written in consecutive instructions), triggering the
232-
forwarding unit.
256+
dependencies between instructions (registers are both read and
257+
written in consecutive instructions), triggering the forwarding
258+
unit.
233259
</li>
234260
<li>
235-
<strong>Control Hazards</strong>: The branch instructions
236-
create control hazards that demonstrate branch prediction and
237-
pipeline flushing.
261+
<strong>Control Hazards</strong>: The multiple branch
262+
instructions create control hazards that demonstrate branch
263+
prediction and pipeline flushing.
238264
</li>
239265
<li>
240-
<strong>Loop Implementation</strong>: The program implements a
241-
simple counting loop that:
266+
<strong>Fibonacci Implementation</strong>: The program
267+
calculates the Fibonacci sequence:
242268
<ul>
243-
<li>Starts with x1 = 3 and x2 = 7</li>
244-
<li>
245-
Adds the current value of x1 to x2 on each iteration
246-
</li>
247-
<li>Decrements x1 by 1 on each iteration</li>
248-
<li>Exits when x1 reaches 0</li>
269+
<li>Loads n=10 from memory location 0</li>
270+
<li>Initializes with Fib(0)=0 and Fib(1)=1</li>
271+
<li>Iteratively computes Fib(n) = Fib(n-1) + Fib(n-2)</li>
272+
<li>For n=10, the result will be Fib(10)=55</li>
249273
</ul>
250274
</li>
251275
</ol>
252276
<p>
253-
When the program completes, x1 will be 0 and x2 will be 7+3+2+1
254-
= 13. By following the execution, you can observe how the
255-
pipeline handles data and control hazards in real-time.
277+
When the program completes, x4 will contain the 10th Fibonacci
278+
number (55). Following the execution shows how the pipeline
279+
handles data dependencies and branch predictions in this more
280+
complex algorithm. The first instruction demonstrates memory
281+
access hazards by loading the value from memory.
256282
</p>
257283
</div>
258284
</div>
@@ -355,7 +381,7 @@ <h2>Sequential vs Pipelined CPU</h2>
355381
</li>
356382
</ul>
357383
</div>
358-
384+
359385
<div id="resources" class="resources">
360386
<h2>Additional Resources</h2>
361387
<div class="resource-links">
@@ -366,7 +392,11 @@ <h4>Design Report</h4>
366392
<p>Detailed documentation of the RISC-V implementation</p>
367393
</div>
368394
</a>
369-
<a href="https://github.com/MostlyKIGuess/RISC-V-Processor-Implementation/" class="resource-btn" target="_blank">
395+
<a
396+
href="https://github.com/MostlyKIGuess/RISC-V-Processor-Implementation/"
397+
class="resource-btn"
398+
target="_blank"
399+
>
370400
<span class="icon">&#xe043;</span>
371401
<div class="resource-info">
372402
<h4>GitHub Repository</h4>
@@ -375,13 +405,12 @@ <h4>GitHub Repository</h4>
375405
</a>
376406
</div>
377407
</div>
378-
408+
379409
<footer>
380410
<p>RISC-V CPU Visualizer</p>
381411
<p>Made with <span class="icon">&#xe87d;</span></p>
382412
<p>&copy; 2025 All rights reserved.</p>
383413
</footer>
384-
385414
</div>
386415
</body>
387416
</html>

0 commit comments

Comments
 (0)