finished the interpreter
This commit is contained in:
+34
-12
@@ -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
|
||||
@@ -69,14 +90,15 @@ loop_start:
|
||||
cmp rg3, zero
|
||||
jeq end
|
||||
|
||||
// if we get here, we don't know what the instruction is
|
||||
end:
|
||||
lwi error, rg2
|
||||
// if we get here, we don't know what the instruction is
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user