From 96e2582af6971e42a64126958dd0dcab5ba4a1e4 Mon Sep 17 00:00:00 2001 From: Alex Williams Date: Thu, 14 Oct 2021 22:26:51 +0900 Subject: [PATCH] Ignore single-line comments in assembly. See #4 --- derzforth.asm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/derzforth.asm b/derzforth.asm index d4fc404..9aeef70 100644 --- a/derzforth.asm +++ b/derzforth.asm @@ -288,7 +288,6 @@ tib_init: li TLEN, 0 # set TLEN to 0 li TPOS, 0 # set TPOS to 0 -# TODO: ignore single-line comments (backslash til newline) # TODO: ignore bounded comments (lparen til rparen) # TODO: bounds check on TBUF (error or overwrite last char?) interpreter_repl: @@ -296,6 +295,10 @@ interpreter_repl: call serial_getc call serial_putc + # check for single-line comment + li t0, '\\' # comments start with \ char + beq a0, t0, interpreter_skip_comment # skip the comment if \ is found + # check for backspace li t0, '\b' bne a0, t0, interpreter_repl_char @@ -311,6 +314,16 @@ interpreter_repl: j interpreter_repl +interpreter_skip_comment: + # read and echo a single char + call serial_getc + call serial_putc + + # skip char until newline is found + li t0, '\n' # newlines start with \n + bne a0, t0, interpreter_skip_comment # loop back to SKIP comment unless newline + j interpreter_repl + interpreter_repl_char: add t0, TBUF, TLEN # t0 = dest addr for this char in TBUF sb a0, 0(t0) # write char into TBUF