assembler still very broken, dependency resolution works, now working on expanding pseudoinstructions

This commit is contained in:
2025-06-17 03:11:22 +01:00
parent 88a1c9f245
commit 87fbd6c362
9 changed files with 604 additions and 292 deletions
+34
View File
@@ -0,0 +1,34 @@
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)
init:
// Initialize the first two Fibonacci numbers
lli 0, rg0 // F(0) = 0
lli 1, rg1 // F(1) = 1
// 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))
// 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
finish:
mov rg1, acc // Final Fibonacci number is in acc
hlt
jmp print::run
View File