Skip to content

tinybasic: clear pend at start - #3

Open
enjoy-digital wants to merge 1 commit into
micro-FPGA:mainfrom
enjoy-digital:tinybasic-pend
Open

enjoy-digital wants to merge 1 commit into
micro-FPGA:mainfrom
enjoy-digital:tinybasic-pend

Conversation

@enjoy-digital

Copy link
Copy Markdown
Contributor

Problem

In examples/lib/tinybasic.bas, pend (the end of the program text) is a register variable in S4. It is set only by NEW, so the interpreter works only when the CPU starts with S4 = 0. The startup code clears the RAM variables, not the registers.

When a boot loader runs first and leaves other values in the registers, the first statement fails: PRINT 2+3*4 gives ? Syntax error, or the interpreter writes outside the program memory. Found with the LiteX BIOS on VexRiscv, which loads the program and jumps to it.

Fix

One line: pend = 0 before the banner.

Tested

In rbsim, with all registers set to 0xDEADBEEF before the start (RV32I, UART0 of the test simulator):

  • without the change: PRINT 2+3*4 fails with a store to an unmapped address;
  • with the change: PRINT 2+3*4 gives 14, a stored FOR / NEXT program and LIST work.

tests/run_tests.py: all tests passed. Not run on the Sapphire SoC (no board here).

Written by an AI agent (Claude Code), supervised by Florent Kermarrec.

🤖 Generated with Claude Code

pend (the end of the program text) is a register variable in S4. It was set only by
NEW, so the interpreter worked only when the CPU starts with S4 = 0. After a boot
loader that leaves other values in the registers (found with the LiteX BIOS on
VexRiscv) the first statement gives "Syntax error" or writes outside the program
memory. The RAM variables are cleared by the startup code, the registers are not.

Tested in rbsim with all registers set to 0xDEADBEEF before the start: without the
change the first PRINT fails, with it PRINT, a stored program and LIST work.

Written by an AI agent (Claude Code), supervised by Florent Kermarrec.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant