I am writing a VHDL code for a MIPS32. My idea is that for simulation purpose the testbench shall replace the instruction memory with a behavioral model which will read the program instructions from an ASCII file written as assembly instructions and convert them to 32 bit words and store them in a std_logic_vector. Thereafter, the input value from the program counter shall decide which of these values in the vector are output.

To this end the behavioral model shall have to read each line in the text file, determine if it contains an actual instruction e.g add, lw, sw e.t.c and then find out the operands given for that instruction and generate an equivalent 32 bit binary instruction. It shall also have to determine if the instruction is valid or has syntax error during this parsing and token generation process. For this purpose I shall require some serious string manipulation functions in VHDL. However, I don't see them in textio which only contains functions to read/write files and not play with string data type.

  • 4
    \$\begingroup\$ Why would you write an assembler in VHDL, rather than using a more conventional programming language (or an existing MIPS assembler) and then loading the resulting binary data into your simulation? \$\endgroup\$
    – Dave Tweed
    Commented Jul 1, 2015 at 20:11
  • \$\begingroup\$ I actually implemented a very primitive SPARC assembler in VHDL, for test benches. It should not be used for large programs, but for testing some race conditions (like interrupts, cache or MMU issues...), interleaving assembly instructions with VHDL code can be quite useful. Look for "TEMLIB" \$\endgroup\$
    – Grabul
    Commented Jul 1, 2015 at 20:47
  • \$\begingroup\$ @Dave, what do you think I should use as assembler? I am merely trying to create a "script driven testbench" which in this case turns out to be very close to an assembler \$\endgroup\$
    – quantum231
    Commented Jul 2, 2015 at 0:15
  • 2
    \$\begingroup\$ Pretty much any scripting language (Perl, Python, PHP, Ruby, etc., etc.) has powerful string manipulation built in and can be used to create a simple assembler. In terms of existing assemblers, gcc (as mentioned in Paebbels answer, is a commonly-used tool. \$\endgroup\$
    – Dave Tweed
    Commented Jul 2, 2015 at 11:57

1 Answer 1


There are string libraries on the net like:

But the normal flow is as follows:

  1. compile your MIPS program (e.g. with gcc and cross platform compiling to a *.elf file.
  2. convert your .elf file to a memory file (.mem, *.hex, *.mif)
  3. load that memory file into your MIPS's boot memory
  4. simulate your program and CPU
  • \$\begingroup\$ The CPU I am implementing does not have the full instruction set. At first I am going to design a single cycle processor with a very limited instruction set, some arithmetic-logic, branch and jump instructions only \$\endgroup\$
    – quantum231
    Commented Jul 2, 2015 at 0:14
  • 2
    \$\begingroup\$ That no problem. On the one side, compilers don't use the full instruction set. On the other side, you can use the assembler to generate only implemented instructions. \$\endgroup\$
    – Paebbels
    Commented Jul 2, 2015 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.