From 6f2bb477acaf01a71794a3c7a9857f038dcdcba9 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Tue, 24 Jun 2025 19:31:55 +0100 Subject: [PATCH] finished the interpreter --- resources/dsa/bf.dsa | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/resources/dsa/bf.dsa b/resources/dsa/bf.dsa index 96b2e60..d87d25f 100644 --- a/resources/dsa/bf.dsa +++ b/resources/dsa/bf.dsa @@ -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