Skip to content

Commit

Permalink
Ignore single-line comments in assembly. See #4
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Oct 14, 2021
1 parent e5f56d0 commit 96e2582
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion derzforth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,17 @@ 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:
# read and echo a single char
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
Expand All @@ -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
Expand Down

0 comments on commit 96e2582

Please sign in to comment.