Alok Menghrajani

Security engineer at Square. Previously co-author of Hack and put the 's' in https at Facebook. Maker of CTFs.

Home | Contact me | Github | Twitter | Facebook

Alexandre Lopes and I designed a MIPS processor. We implemented the processor in VHDL and tested it on a reprogrammable (FPGA) chip.

We worked with Mentor Graphics' development suit (ModelSim, Leonardo and HDL Designer). These tools were used to simulate our processor on a desktop computer.

We also used a MIPS emulator to help debug things.

In order to manipulate data, two components are required: an algorithm (that will instruct how to manipulate the data) and hardware resources (that will do the actual manipulation).

A processor is a system that has some hardware resources, access to the data (in our case via the RAM) and a way to understand and execute instructions (in our case the instructions are in the ROM). The main parts of a processor are:

  • ALU (arithmetic logic unit)

    This part is responsible for performing basic operations such as addition, substraction, AND, OR, etc...

  • Register File

    The register file is a special memory (known as registers) that is accessible very quickly (because it is inside the processor). These registers are used to store the intermediate results of calculations (because it is easier and more efficient to design the instructions to use these registers rather than the RAM). We had 32 registers.

  • 3 data buses and 2 address buses

    The buses allow data to be exchanged between the registers and the RAM and ROM.

  • PC (program counter)

    The PC is a special register, used to keep track of what is the next instruction to be executed.

  • Control Unit

    The control unit is used to manage the above resources. It is implemented as a state machine. We implemented all these parts and inter-connected them to form the datapath. Our processor is very simple and understands 8 instructions (addition, substraction, logic AND, logic OR, immediate add, conditional branch, loading and storing data in RAM). The reason our processor is simple is because it does not have a pipeline or virtual memory support.

This pdf contains source code (vhdl) and some docs (french).

prime.asm is a test application we wrote in assembly. We compute a list of prime numbers. We were proud to be able to do this, considering we didn't have multiplication or division instructions.