Towards a better assembler, still in VHDL, sans Lex & Yacc

A project log for YGREC8

A byte-wide stripped-down version of the YGREC16 architecture

yann-guidon-ygdesYann Guidon / YGDES 11/06/2021 at 05:040 Comments

More and more, I'm looking at the YASEP's JavaScript framework and want to reuse it to develop better programs for the YGREC. This would be great to explore the practical limitations of the Y8...

Then I realise how outdated, clunky, messy and unmanageable #YGWM still is :-/

And I don't want to use C stuff : I have committed to using only bash and VHDL.

And here we are...

The project already provides YGREC8/ASM/Y8asm.vhdl but this is useful only for inline, context-less instructions. I want to create/write/assemble/run real programs, generate .HYX files and load them for simulation.

Without EVEN starting to deal with all the parsing, two critical parts are already required :

  1. The .HYX filter (only a C in/out filter is available so far)
  2. The symbols table.


I think I'll start with 1. because the algorithms are already written in C and JS.

Then, I'll deal with the dynamic allocation of symbols. I have chosen to use a unified table where the opcodes, the pseudo-opcodes, the unknown symbols and the defined symbols are kept together, to keep the complexity low and ensure there is no "shadowing", such as redefnition of opcodes, numbers etc. (as was the case in the buggy YASEP assembler in JS, where I lazily used string substitutions as a shortcut and it could totally break everything...)

Update: drawing from the YASM experience, the assembler should use a collection of dictionaries, first the pseudocodes and opcodes, then the local symbols, then the global symbols, eventually more, such that function nesting becomes possible (for example) and important things don't get re-defined. At first, only a global symbol table will be defined but more should be able to be allocated and de-allocated. A kind of linked list of symbol tables will ensure precedence.

Ephemeral Local symbol tables will be useful for the macros, for example. In this context, some inspiration from C syntax will help: the pseudo-symbol '{'  would create one table and '}' destroys the last created.

Preprocessing would use m4.


OK, as usual, I say something then do the contrary, so here is dictionary.vhdl.

"Methods" are provided to create a dictionary, look it up, add a symbol and flush the whole dictionary. The idea being that there is one dictionary per context and the contexts can be stacked with "{" and unstacked/flushed by "}".

That will make the assembler way easier to write, and now I need to handle .HYX files...


20211112: a few days of passionate work and YGREC8_VHDL.20211112.tgz is now available !

It's missing at least two important features: arithmetic expressions and symbol definition&update. Anyway it's starting to be useful to write simple programs. It's a bit bloated and requires some refactoring but it's only 741 lines so far (not including a few external packages).

I have so far been very, overly confident maybe, about the use of the ISA and now I'll be able to prove its worth.


20211118: YGREC8_VHDL.20211118.tgz provides a refactored assembler that supports more features and works better. I am now able to write whole programs!

And it's all written in VHDL, 700 lines so far.