Skip to content

Commit 7aa37cd

Browse files
final changes and complex code testing
fibonacci and factorial and changes in readme and html
1 parent 6333185 commit 7aa37cd

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ cd sequential
99
chmod +x test_sequential.sh
1010
./test_sequential.sh <filename>.s
1111
```
12+
Based on the provided code, I'll summarize the assembler's functions and features for assembly code processing:
1213

14+
## Assembly Instructions Supported
15+
16+
The assembler supports a subset of RISC-V instructions:
17+
- **R-type**: `add`, `sub`, `or`, `and`
18+
- **I-type**: `addi`, `ld` (load doubleword)
19+
- **S-type**: `sd` (store doubleword)
20+
- **B-type**: `beq` (branch if equal)
21+
- **Special**: `nop` (no operation)
1322

1423
NOTES:
1524
- `ld` and `sd` are used to load and store double words. But, they use the same instructions as `lw` and `sw` that are not implemented in this version.

sequential/testcases/11.s

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
start:
2+
addi x10, x0, 10 # Load n
3+
addi x11, x0, 0 # x11 = 0 (Fib(0))
4+
addi x12, x0, 1 # x12 = 1 (Fib(1))
5+
beq x10, x0, done # If n == 0, return Fib(0)
6+
addi x10, x10, -1 # Decrement n by 1 to account for Fib(1)
7+
beq x10, x0, done1 # If n == 1, return Fib(1)
8+
9+
loop:
10+
add x13, x11, x12 # x13 = x11 + x12 (Fib(n) = Fib(n-1) + Fib(n-2))
11+
add x11, x12, x0 # x11 = x12 (shift Fib(n-1) to Fib(n-2))
12+
add x12, x13, x0 # x12 = x13 (shift Fib(n) to Fib(n-1))
13+
addi x10, x10, -1 # Decrement n
14+
beq x10, x0, done1 # Repeat until n == 0
15+
beq x0, x0, loop
16+
17+
done1:
18+
add x13, x12, x0 # Return Fib(1)
19+
20+
done:
21+
# x13 holds the Fibonacci result
22+
nop

sequential/testcases/12.s

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
start:
2+
addi x10, x0, 10 # Load n
3+
addi x11, x0, 1 # x11 = 1 (accumulator for factorial)
4+
beq x10, x0, done # If n == 0, factorial is 1
5+
6+
loop:
7+
add x12, x0, x11 # x12 = x11 (initialize for multiplication)
8+
add x13, x0, x10 # x13 = x10 (multiplier counter)
9+
addi x11, x0, 0 # Reset x11 to 0
10+
11+
mul_loop:
12+
beq x13, x0, end_mul # If x13 == 0, end multiplication
13+
add x11, x11, x12 # x11 = x11 + x12 (multiplication by addition)
14+
addi x13, x13, -1 # Decrement multiplier counter
15+
beq x0, x0, mul_loop # Continue multiplication loop
16+
17+
end_mul:
18+
addi x10, x10, -1 # Decrement x10 by 1
19+
beq x10, x0, done # If x10 != 0, repeat loop
20+
beq x0, x0, loop
21+
22+
done:
23+
# x11 holds the factorial result
24+
nop # End program (can replace with ecall to exit in real environment)

sequential/visualization/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ <h1>RISC-V CPU Visualizer</h1>
1717
<button id="play-pause">Play</button>
1818
<select id="speed">
1919
<option value="1000">1x Speed</option>
20-
<option value="500">2x Speed</option>
2120
<option value="200">5x Speed</option>
21+
<option value="100">10x Speed</option>
22+
<option value="20">50x Speed</option>
2223
</select>
2324
</div>
2425
</div>

0 commit comments

Comments
 (0)