GitPedia

MSW

A simple 16-bit CPU built in Logisim

From Theldus·Updated April 17, 2026·View on GitHub·

MSW is a 16-bit CPU, RISC, Unicycle, Harvard, built in [Logisim](http://www.cburch.com/logisim/). The project is written primarily in Java, distributed under the GNU General Public License v3.0 license, first published in 2016. Key topics include: 16-bit, architecture, circuit, cpu, logisim.

MSW - Machine with Shuffled Wires

MSW is a 16-bit CPU, RISC, Unicycle, Harvard, built in Logisim.

It is designed to be as simple as possible, so it is not cumbersome to understand the entire circuit, as well as the instruction set and the assembler. It is primarily suitable for students of Computer Architecture. Because of this, it has no pipeline, branch prediction, cache, among other features.

<p align="center"> <img align="center" src="http://i.imgur.com/XRXsxBN.png" alt="msw overview"> <br> <i>MSW Overview</i> </p>

Architecture

Inspired by the Intel 8086 and MIPS, but much simpler, its instruction set has 16 instructions and similar registers with Intel. Its general architecture looks like a MIPS unicycle.

It is divided into 4 parts:

  • ALU: Arithmetic Logic Unit
  • UControl: Unity Control, responsible for creating control flags throughout the CPU, according to the instruction currently running.
  • BRegs: Register Bank.
  • CPU: Final module, containing the full assembly of the other modules.

Instruction Set

The MSW's instructions follows the format below:

 OpCode      R1   R2              Imm
/-------\    /-\ /-\     /------------------\    - Immediate instructions.
 0 0 0 0     0 0 0 0     0 0 0 0      0 0 0 0

and

OpCode      R1   R2           Constant
/-------\    /-\ /-\     /------------------\    - Only registers.
 0 0 0 0     0 0 0 0     1 1 1 1      1 1 1 1

Supports 16 instructions and 4 registers: AX, BX, CX and DX.
* Due the use of 0x00FF to identify Register-only instructions, you shouldn't use 255 as immediate value.

The following table illustrates all instructions:

Op CodeInstructionBehavior
0OR REGDest,REGSource/ImmREGDest <- REGDest | REGSource
1NOT REGDestREGDest <- ~REGDest
2AND REGDest,REGSource/ImmREGDest <- REGDest & REGOri
3XOR REGDest,REGSource/ImmREGDest <- REGDest ^ REGOri
4ADD REGDest,REGSource/ImmREGDest <- REGDest + REGOri
5SUB REGDest,REGSource/ImmREGDest <- REGDest - REGOri
6MULT REGDest,REGSource/ImmREGDest <- REGDest * REGOri
7DIV REGDest,REGSource/ImmREGDest <- REGDest / REGOri
8MOV REGDest, REGSourceREGDest <- REGSource
9MOV REGDest, ImmREGDest <- Imm
10LOAD REGDest, REGSourceREGDest <- MEM[REGSource]
11STORE REGDest, REGSourceMEM[REGDest] <- REGSource
12JMPZ REGDest/LabelJuMP if Zero
13JMPN REGDest/LabelJuMP if Negative
14JMPP REGDest/LabelJuMP if Positive
15HALTHalts CPU

Assembler

In order to avoid programming directly in binary, MSW also comes with an Assembler, that takes a file as input and generates a hex file ready to run. A code like below can be perfectly executed on the CPU:

##################
##FibonAsm, ^.^###
##################

#Calculation of Fibonacci

mov ax,1   #i
xor bx,bx  #j
xor cx,cx  #<-- mem
mov dx,14  #counter

fibo:
	add   ax,bx  #i=i+j
	store cx,ax  #mem[0] = i
	mov   ax,bx  #i=j
	load  bx,cx  #j=mem[0]
	sub   dx,1   #count=count-1
	jmpp  fibo
halt

#Result in bx

The assembler is case insensitive for instruction names, supports labels and comments.

To run the generated program (.hex), just load it to the leftmost memory and activate the clock.
Here is a video of the CPU
in operation (Portuguese).

What comes next?

This is my first CPU and I believe there are some design issues in both the CPU and the Assembler (not bugs, just the way
I developed).

So I don't intend to go far with it, there are still some things I want to add such as stack and I/O instructions, but
the ideal would be a re-work on a new CPU, very different from this first, starting with microcode addition eg.


That's it, if you have questions, suggestions or want to contribute, feel free to ask me, I would love hear from you.

Contributors

Showing top 1 contributor by commit count.

View all contributors on GitHub →

This article is auto-generated from Theldus/MSW via the GitHub API.Last fetched: 6/28/2026