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
+16 -19
View File
@@ -1,28 +1,25 @@
dw stack: 0x10000
dw screen: 0x20000
db string: "Dominos sucks!"
db string2: 0, 1, 2, 3, 4, 5, 6
db length: 14
// PRINT LIBRARY.
// don't run this as a program as it won't do anything useful.
init:
ldw stack, bpr
mov bpr, spr
dw display: 0x20000
start:
ldb length, rg0
lwi rg1, string
lwi rg2, display
pop ret // return address
pop rg0 // length
pop rg1 // string
ldw display, rg2
loop:
// read from string and write to display
ldb rg1, rg3, rg4
stb rg3, rg1, rg4
ldw rg1, acc
stw acc, rg2
// increment the offset & decrement the loop counter
inc rg4
dec rg0
// if loop counter <= 0 return.
cmp rg0, zero,
jgt loop
iadd rg1, 4
iadd rg2, 4
cmp rg0, zero
jge loop
end:
jmp ret
+36
View File
@@ -0,0 +1,36 @@
dw string: "this is some random string idk"
dw len: 8
start:
// we use lwi in this case because
// in a generic case 'string' could be a 32 bit addr
lwi string, rg1
push rg1
lwi len, rg1
push rg1
push pcx
jmp start
hlt
dw display: 0x20000
print:
pop ret // return address
pop rg0 // length
pop rg1 // string
ldw display, rg2
loop:
ldw rg1, acc
stw acc, rg2
dec rg0
iadd rg1, 4
iadd rg2, 4
cmp rg0, zero
jge loop
end:
jmp 4, ret
Binary file not shown.