Update assembler/usage

2025-06-19 18:07:57 +01:00
parent f1ca75fd09
commit 3af03f58f8
+83
@@ -775,8 +775,58 @@ include fib "../resources/dsa/fib.dsa"
``` ```
## Example Programs and libraries. ## Example Programs and libraries.
```dsa
// lib:
// print.dsa
// usage:
//
// include print "<relative path>""
//
// usage for print:
// push (register containing address of string)
// push pcx
// jmp print::print
//
// usage for reset:
// push pcx
// jmp print::reset
dw display: 0x20000
dw current: 0x20000
reset:
pop ret
ldw display, rg1
stw rg1, current
jmp 4, ret
print:
pop ret // return address
pop rg0 // string
ldw current, rg1
loop:
ldb rg0, acc
stb acc, rg1
iadd rg0, 1
iadd rg1, 1
cmp acc, zero
jne loop
// return
end:
// set current to
stw rg1, current
jmp 4, ret
```
```dsa ```dsa
// lib:
// fib.dsa
// this is a simple library to calculate the fibonacci sequence up to n, writing each value to the stack. // this is a simple library to calculate the fibonacci sequence up to n, writing each value to the stack.
fib_n: fib_n:
@@ -799,6 +849,39 @@ start:
jmp 4, ret jmp 4, ret
``` ```
```dsa
include print "print.dsa"
include fib "fib.dsa"
dw stack: 0x10000
db string: "An idiot admires complexity, a genius admires simplicity,
a physicist tries to make it simple, for an idiot anything the more complicated it is,
the more he will admire it, if you make something so clusterfucked he can't understand it he's
gonna think you're a god cause you made it so complicated nobody can understand it.
That's how they write journals in Academics, they try to make it so complicated people think you're a genius"
init:
ldw stack, bpr
mov bpr, spr
start:
lwi string, rg1
// push variables
push rg1 // string address.
push pcx // return address.
// call
jmp print::print
lli 25, rg0
push rg0
push pcx
jmp fib::fib_n
hlt
```