finished the interpreter

This commit is contained in:
2025-06-24 19:31:55 +01:00
committed by J. Hinchliffe
parent d87bf6bbb0
commit 6f2bb477ac
+32 -10
View File
@@ -5,7 +5,35 @@
include print "./lib/print.dsa" include print "./lib/print.dsa"
// "print hello world" // "print hello world"
db program: "++++++[>++++++++++++<-]>.>++++++++++[>++++++++++<-]>+.+++++++..+++.>++++[>+++++++++++<-]>.<+++[>----<-]>.<<<<<+++[>+++++<-]>.>>.+++.------.--------.>>+." db program: "++++++++++++++++++++++++++++++++++++++++++++
>++++++++++++++++++++++++++++++++
>++++++++++++++++
>
>+
<<
[
>>
>
>++++++++++
<<
[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]
>[<+>-]
>[-]
>>
>++++++++++
<
[->-[>+>>]>[+[-<+>]>+>>]<<<<<]
>[-]
>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]
<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]
<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-]
<<<<<<<.>.
>>[>>+<<-]
>[>+<<+>-]
>[<+>-]
<<<-
]
<<++..."
db error: "Invalid Instruction!" db error: "Invalid Instruction!"
dw stack: 0x10000 dw stack: 0x10000
@@ -41,13 +69,6 @@ loop_start:
// load the current instruction into rg3 // load the current instruction into rg3
ldb rg0, rg3 ldb rg0, rg3
pusha 2
push rg3
call print::print_byte
pop zero
popa 2
// switch on the instruction // switch on the instruction
// all cases will return to either loop_start or loop_end // all cases will return to either loop_start or loop_end
cmp rg3, rg8 cmp rg3, rg8
@@ -70,13 +91,14 @@ loop_start:
jeq end jeq end
// if we get here, we don't know what the instruction is // if we get here, we don't know what the instruction is
end:
lwi error, rg2 lwi error, rg2
pusha 2 pusha 2
push rg2 push rg2
call print::print call print::print
pop zero pop zero
popa 2 popa 2
end:
hlt hlt
loop_end: loop_end:
@@ -106,7 +128,7 @@ inc_ptr:
// ------------------------------------------ // ------------------------------------------
// decrement the pointer // decrement the pointer
dec_ptr: dec_ptr:
stw rg1, rg2 stw rg2, rg1
subi rg1, 4 subi rg1, 4
ldw rg1, rg2 ldw rg1, rg2
jmp loop_end jmp loop_end