IT WORKS HELL YEAH.

This commit is contained in:
2025-06-18 22:53:01 +01:00
parent 1210b19333
commit e281bc2d1d
26 changed files with 715 additions and 188 deletions
+14 -21
View File
@@ -1,34 +1,27 @@
// include print "../resources/dsa/print.dsa"
// Fibonacci sequence calculator in DSA assembly
// Calculates the first 8 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13
dw fib_count: 6 // How many more numbers to calculate after F(0) and F(1)
db fib_count: 10 // How many more numbers to calculate after F(0) and F(1)
init:
// Initialize the first two Fibonacci numbers
lli rg0, 0 // F(0) = 0
lli rg1, 1 // F(1) = 1
lli 0, rg0 // F(0) = 0
lli 1, rg1 // F(1) = 1
ldb fib_count, rg2
loop:
add rg0, rg1, acc // rg4 = rg0 + rg1 (new Fibonacci number)
push rg0
// Load loop counter
ldw fib_count, zero, rg2 // Load number of iterations remaining
fibonacci_loop:
// Calculate next Fibonacci number: F(n) = F(n-1) + F(n-2)
add rg0, rg1, rg4 // rg4 = rg0 + rg1 (new Fibonacci number)
// Shift the sequence forward
mov rg1, rg0 // rg0 = previous rg1 (F(n-2) = F(n-1))
mov rg4, rg1 // rg1 = rg4 (F(n-1) = F(n))
mov acc, rg1 // rg1 = rg4 (F(n-1) = F(n))
// Decrement loop counter
dec rg2 // rg2 = rg2 - 1
// Check if we should continue looping
cmp rg2, zero // Compare counter with 0
jgt fibonacci_loop // Jump back if counter > 0
jgt loop // Jump back if counter > 0
finish:
mov rg1, acc // Final Fibonacci number is in acc
push rg0,
push rg1,
// Final Fibonacci number is in rg1
hlt
jmp print::run
// jmp print::run