$ man tshabbic.projects.my-cpu
MY-CPU(8)Custom CPU Architecture, Instruction Set, and AssemblerMY-CPU(8)
Name

my-cpu -- custom cpu architecture, instruction set, and assembler

Description

[See the Assembler's Source Code!] [See the Documentation!]

my-cpu is a single-cycle 16-bit CPU I designed from scratch in Logism Evolution, along with its own instruction set and a Python assembler. It features the core parts of a datapath: a program counter, instruction memory, a register file, an ALU, and data memory.

The CPU has four 8-bit general-purpose registers (X0-X3) and a 256-byte data memory. It supports four instructions: ADD and SUB (register plus an 8-bit immediate) and LDR and STR (using the immediate as the memory address). Each 16-bit instruction packs the following into one word: read and write register IDs, a register-write enable bit, an add/subtract select bit, a two-bit load/store field, and the 8-bit immediate.

Note that because the encoding is this direct, the datapath doesn't necessarily need a separate control unit or ALU control. The control signals come straight from bits of the instruction! Also, for extra credit as per the assignment spec, I added a pair of two-digit hex displays to show register and memory values while a program runs!

The assembler is a dependency-free Python 3.11 script. It translates a text file of the CPU's Assembly Language into a hex image that loads directly into the CPU's instruction memory. See the documentation, which covers the architecture, the assembler workflow, and the binary encoding of every instruction, with the reasoning behind each field width.


The CPU itself inside Logism-Evolution (You may need to zoom in)

Bugs

The LDR instruction can sometimes fail, leaving a simulated register in a corrupted state:

Hex Instructions: 0210 0040 009F
Expected Behavior: Adds 2 to X0. Stores X0 (2) to M[0]. Loads M[0] into X3
Observed Behavior: Adds 2 to X0. Stores X0 (2) to M[0]. Fails to load M[0] into X3 (Displayed as: ??)
After discussion with my Professor, this was considered a non-issue (for the purposes of this assignment) and may be a limitation of the software.

The comments in the Assembler Source file are rather... not that useful overall, but did come from this course's habit of requiring we comment most if not every line in our source files.

Usage

See the provided documentation for assembler usage details.

History

This project was performed during Fall of 2023 for CS 382 - Computer Architecture and Organization @ Stevens' Institute of Technology.