Electronic – If I am writing a processor in VHDL, how can I get an assembler to ease testing

assemblermicroprocessorvhdl

Provided that I have written a simple microprocessor design in VHDL where I have decided what instructions it has to do each task, I will then have to write test code in machine language which is tedious and error prone.

A simple assembler would be like a “lite text processor” where it can convert assembly instructions to machine code by parsing text of the assembly language program. Each assembly instruction is a mnemonic and the parser will also figure our how to fit the parameters into the generated machine instruction word e.g register name, variable name e.t.c

Is there an easy solution to developer an assembler of such a nature?

Best Answer

Puh, writing an assembler would actually imply writing a parser, and then writing some kind of Abstract syntax Tree-to-instructions converter.

I think this would, if you want to do it most simple, be done by defining a grammar (ie a set of instructions and registers and immediate value formats and how to combine them) and then generating a parser for that. You can go the Bison/Yacc/flex way about that, but I hear good things about ANTLR, so I'd give that a try.

In the medium run, you'd probably want to implement a clang or GCC backend. That would have the "nice" side effect that you could then compile e.g. C to your instruction set.