dsa lib bugfixes

This commit is contained in:
2025-06-26 20:53:51 +01:00
parent 7c63340888
commit ae92510fb8
5 changed files with 88 additions and 20 deletions
+23 -5
View File
@@ -65,7 +65,19 @@ print_word:
ldw bpr, rg0, 8
ldw current, rg1
stw rg0, rg1
addi rg1, 3
stb rg0, rg1
subi rg1, 1
shr rg0, 8
stb rg0, rg1
subi rg1, 1
shr rg0, 8
stb rg0, rg1
subi rg1, 1
shr rg0, 8
stb rg0, rg1
addi rg1, 4
jmp _end
@@ -175,18 +187,24 @@ print_newline:
push bpr
mov spr, bpr
// load variables into registers
ldw display, rg0
ldw current, rg1
// get the offset from the display base
sub rg1, rg0, rg0
lwi 80, rg2
pusha 3
push rg0
push rg2
call maths::divmod
pop rg2
addi rg2, 80
ldw display, rg1
add rg1, rg2, rg1
pop zero // result
pop rg3 // remainder
popa 3
sub rg1, rg3, rg2
addi rg2, 80, rg1
// _end saves the display state
jmp _end
+9 -8
View File
@@ -4,24 +4,25 @@ fib_n:
push bpr
mov spr, bpr
ldw bpr, rg1, 8 // load op 2
ldw bpr, rg0, 8 // load arg
mov rg1, rg2
lwi 1, rg1
start:
mov rg1, rg2
add rg1, rg2, acc
add rg1, rg2, rg3
pusha 4
push rg1
call print::print_hex_word
pop rg1
call print::print_hex_byte
call print::print_newline
pop zero
popa 4
mov rg2, rg1
mov acc, rg2
mov rg3, rg2
cmp rg0, zero
dec rg0
cmp rg0, zero
jgt start
stw rg1, bpr, 8
+54 -2
View File
@@ -1,3 +1,7 @@
include fib: "./lib/maths/fib.dsa"
include maths: "./lib/maths/core.dsa"
include print: "./lib/io/print.dsa"
dw idt: 0xFFFF0000
dw stack: 0x10000
init:
@@ -9,11 +13,59 @@ init:
ldw stack, bpr
mov bpr, spr
dw string: "hello world"
start:
lwi 10, rg0
lwi 37, rg0
lwi 12, rg1
push rg0
call maths::fib_n
push rg1
call maths::divmod
pop rg0 // result
pop rg1 // remainder
push rg1
push rg0
call print::print_hex_byte
call print::print_whitespace
pop zero
call print::print_hex_byte
call print::print_newline
lwi string, rg0
//lwi 10, rg0
pusha 4
push rg0
call print::print
//call fib::fib_n
pop zero
call print::print_newline
popa 4
pusha 4
push rg0
call print::print
//call fib::fib_n
pop zero
call print::print_newline
popa 4
pusha 4
push rg0
call print::print
//call fib::fib_n
pop zero
call print::print_newline
popa 4
pusha 4
push rg0
call print::print
//call fib::fib_n
pop zero
call print::print_newline
popa 4
hlt
// fault handler in case we fail DSA.
-3
View File
@@ -64,9 +64,6 @@ start:
call print::print
pop zero
lli 3, rg0
ldw rg0, rg0
hlt