finished the interpreter

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