1. 8

This is an 8-bit microcontroller I implemented in Verilog. The ISA is custom-designed to be easy to implement, but it is largely inspired by the PIC architecture. The Verilog implementation can be used on an Arrow SoCKit FPGA board. An assembler and emulator are also included in the repo.


  2. 3

    Holy crap, nice work man!

    I think it would useful to know why you did certain intermediate steps. Would be good if you commented some Verilog code, or showed us how the whole system is connected together and how it works. A big picture would be useful for this type of project as its not immediately obvious.

    Some questions:

    You have two org statements in led_switch.asm… normally there is only one in PIC?

    How is the compiled hex file used in the fpga?

    Why did you choose those megafunctions? What is their purpose?

    Why is OCaml used here for the assembler? could something else have been used?

    Anyways, I will download and try the steps and give it a shot on my DE1 soon.

    Thanks for open sourcing it! Good source for learning.

    1. 2
      1. The first .org statement is not really necessary, since the assembler starts at 0 anyway.
      2. The Altera megafunction for the instruction memory uses the .hex file as it’s initialization.
      3. I’m more familiar with ocamllex and ocamlyacc than any other language processing tools. I could have done it in any language, but I decided to stick to what I know (not that OCaml isn’t awesome).
      1. 2

        Just realized I missed a question. The two megafunctions are for the instruction memory and data memory. They are necessary in order to use the block RAM on the CPU.

        1. 1


          Re 3: When you say any other language - what about python? or is there something OCaml offers for this task?

          1. 1

            OCaml has pretty awesome tooling for writing compilers and other language processors IMO. When you are creating a compiler, you want a good lexer generator and parser generator. OCaml comes with a lexer and parser generator included, called ocamllex and ocamlyacc, respectively. For this project I used menhir instead of ocamlyacc because it has better warnings and error messages. The syntax that menhir uses is compatible with ocamlyacc though, so you don’t have to change any code if you want to switch.

            Another benefit of using OCaml for compilers is that you have algebraic data types, which are very good for creating intermediate representations such as an abstract syntax tree (or in the case of my assembler, a list of instructions). OCaml also has pattern matching, which lets you describe traversals of your intermediate representation very easily.

            If you are interested in writing a compiler or interpreter, I highly recommend learning OCaml. However, most other languages have similar tools. For C, there is the original lex and yacc programs. For Python there is PLY (Python Lex/Yacc). I chose OCaml because I’m most familiar with writing compilers in OCaml since that’s what I learned in school.