Three ways to get a RISC-V CPU in Logisim
| Option | What you get | We tested |
|---|---|---|
| Built-in Risc V IM simulator (System On a Chip library) | A ready-made simulated core | no |
| A community CPU built from gates | A design to study and run | opened, not run |
| Your own single-cycle datapath | The learning, and a core you understand | yes, nine instructions |
The built-in RISC-V (System On a Chip library)
5.0.0 has a System On a Chip library. Our component data lists these parts in it: Risc V IM simulator, Nios2s simulator, SoC bus simulator, Memory simulator, Parallel input/output expander, VGA screen, DMA engine, JTAG UART. We did not place any of them, load a program or use the assembler, so we do not describe the steps. It is a simulated processor: you will not see gates inside it.
Community RISC-V and MIPS CPUs
| T-K-233/RISC-V-Single-Cycle-CPU | RISC-V RV32I | single-cycle | 2.14.6 | MIT | 2025-02-06 | loads, opens, state changes with ticks |
| meiniKi/RV32I_SC_Logisim | RISC-V RV32I | single-cycle | 3.7.2 | MIT | 2023-05-17 | loads, opens, state changes with ticks |
| RayZh-hs/Logisim-RISCV | RISC-V (experimental subset) | not stated | 3.9.0 | MIT | 2025-02-17 | loads, opens (ALU/control files; not run) |
| yuxincs/MIPS-CPU | MIPS | single-cycle and pipelined | 2.7.1 | MIT | 2022-07-17 | loads with a compatibility prompt; its README says Evolution is not supported; not run |
No projects match.
We chose projects with an MIT licence stated in the repository that are not course-solution repositories by name. For each we read the licence and README, checked that no .circ file loads a JAR library, loaded the main circuit headless and in the window of 5.0.0, and switched ticks on to see whether the simulation changes (F127).
Check each licence and README yourself. GitHub’s search also found many projects with no licence stated; we left those out.
Single-cycle datapath, explained
In a single-cycle core, every instruction finishes in one clock cycle: fetch, decode and read registers, execute, access memory, write back. Everything below is in our core.
- Program counter and instruction memory. A 32-bit Register holds the PC. An Adder makes PC + 4. The instruction ROM has 256 words of 32 bits, labelled imem; its address is PC bits 9 to 2, cut out with a Splitter.
- Register file. x1 to x31 are 31 Registers of 32 bits; x0 is a constant 0. A Decoder with 5 select bits and Include Enable? turns the destination number into one write enable (the enable is the control signal reg_we). Two 32-input Multiplexers are the read ports.
- Immediate generator. The I, S and B immediates are rebuilt from instruction bits with Splitters, then widened to 32 bits by a Bit Extender set to sign extension. The B immediate has bit 0 fixed at 0.
- ALU. An Adder, a Subtractor, a 32-bit AND, a 32-bit OR and a signed Comparator for set-less-than feed an 8-input Multiplexer.
- Data memory. A RAM with 256 words of 32 bits and Asynchronous read set to Yes; its address is the ALU result bits 9 to 2, so only word-aligned lw and sw work.
- Branch. A Comparator on the two register values gives beq; the next PC is PC + immediate when the branch is taken, else PC + 4.
- Control. A 128-word ROM addressed by the opcode gives the control bits; a 64-word ROM addressed by is_r, branch, funct3 and funct7 bit 30 gives the ALU select.
Build the minimal RV32I core
Supported instructions: add, sub, and, or and slt (opcode 0110011), addi (0010011), lw (0000011), sw (0100011) and beq (1100011). Every other opcode does nothing except advance the PC; that is a limit of our core. The run ends when the instruction at the PC is 0x00000063 (beq x0, x0, 0, a jump to itself) or 0x00000000. Output pins a0 (x10) and a1 (x11) show the two registers; there is no reset pin, so the PC and registers start at 0.
| 0110011 | add, sub, and, or, slt | reg_we, is_r |
|---|---|---|
| 0010011 | addi | reg_we, alu_src |
| 0000011 | lw | reg_we, alu_src, mem_to_reg |
| 0100011 | sw | alu_src, mem_we, store |
| 1100011 | beq | branch |
No rows match.
Describe this circuit
Components: Clock 1; Constant 1; Constant 2; Constant 3; Constant 4; Constant 5; Register pc; Adder 1; Splitter 1; ROM imem; Splitter 2; Splitter 3; Splitter 4; Splitter 5; Bit Extender 1; Bit Extender 2; Bit Extender 3; ROM control; Splitter 6; Splitter 7; Splitter 8; ROM alu control; Decoder 1; Splitter 9; Register x1; Register x2; Register x3; Register x4; Register x5; Register x6; Register x7; Register x8; Register x9; Register x10; Register x11; Register x12; Register x13; Register x14; Register x15; Register x16; Register x17; Register x18; Register x19; Register x20; Register x21; Register x22; Register x23; Register x24; Register x25; Register x26; Register x27; Register x28; Register x29; Register x30; Register x31; Multiplexer 1; Multiplexer 2; Multiplexer 3; Multiplexer 4; Adder 2; Subtractor 1; AND Gate 1; OR Gate 1; Comparator 1; Bit Extender 4; Multiplexer 5; Splitter 10; RAM data; Constant 6; Multiplexer 6; Comparator 2; AND Gate 2; Adder 3; Multiplexer 7; Constant 7; Comparator 3; Comparator 4; OR Gate 2; Output pin a0; Output pin a1; Output pin halt.
- Clock 1 connects to Register pc, Register x1, Register x2, Register x3, Register x4, Register x5, Register x6, Register x7, Register x8, Register x9, Register x10, Register x11, Register x12, Register x13, Register x14, Register x15, Register x16, Register x17, Register x18, Register x19, Register x20, Register x21, Register x22, Register x23, Register x24, Register x25, Register x26, Register x27, Register x28, Register x29, Register x30, Register x31, RAM data (net clk).
- Constant 1 connects to Adder 1 (net four), 32 bits wide.
- Constant 2 connects to Multiplexer 1, Multiplexer 2 (net x0), 32 bits wide.
- Constant 3 connects to Register pc, Splitter 5, Register x1, Register x2, Register x3, Register x4, Register x5, Register x6, Register x7, Register x8, Register x9, Register x10, Register x11, Register x12, Register x13, Register x14, Register x15, Register x16, Register x17, Register x18, Register x19, Register x20, Register x21, Register x22, Register x23, Register x24, Register x25, Register x26, Register x27, Register x28, Register x29, Register x30, Register x31 (net gnd1).
- Constant 4 connects to Multiplexer 5, Comparator 4 (net zero32), 32 bits wide.
- Constant 5 connects to Register pc (net one1).
- Register pc connects to Adder 1, Splitter 1, Adder 3 (net pc), 32 bits wide.
- Register pc connects to Multiplexer 7 (net pc_next), 32 bits wide.
- Adder 1 connects to Multiplexer 7 (net pc4), 32 bits wide.
- Splitter 1 connects to ROM imem (net iaddr), 8 bits wide.
- ROM imem connects to Splitter 2, Splitter 8, Splitter 9, Comparator 3, Comparator 4 (net instr), 32 bits wide.
- Splitter 2 connects to ROM control (net op), 8 bits wide.
- Splitter 2 connects to Splitter 4, Splitter 5 (net b7).
- Splitter 2 connects to Splitter 4, Splitter 5 (net b8_11), 4 bits wide.
- Splitter 2 connects to Splitter 7 (net f3), 3 bits wide.
- Splitter 2 connects to Multiplexer 1 (net rs1), 5 bits wide.
- Splitter 2 connects to Splitter 3, Multiplexer 2 (net rs2), 5 bits wide.
- Splitter 2 connects to Splitter 3, Splitter 4, Splitter 5 (net b25_30), 6 bits wide.
- Splitter 2 connects to Splitter 3, Splitter 4, Splitter 5 (net b31).
- Splitter 3 connects to Bit Extender 1 (net imm_i12), 12 bits wide.
- Splitter 4 connects to Bit Extender 2 (net imm_s12), 12 bits wide.
- Splitter 5 connects to Bit Extender 3 (net imm_b13), 13 bits wide.
- Bit Extender 1 connects to Multiplexer 3 (net imm_i), 32 bits wide.
- Bit Extender 2 connects to Multiplexer 3 (net imm_s), 32 bits wide.
- Bit Extender 3 connects to Adder 3 (net imm_b), 32 bits wide.
- ROM control connects to Splitter 6 (net ctl), 8 bits wide.
- Splitter 6 connects to Decoder 1 (net reg_we).
- Splitter 6 connects to Multiplexer 4 (net alu_src).
- Splitter 6 connects to RAM data (net mem_we).
- Splitter 6 connects to Multiplexer 6 (net mem_to_reg).
- Splitter 6 connects to Splitter 7, AND Gate 2 (net branch).
- Splitter 6 connects to Splitter 7 (net is_r).
- Splitter 6 connects to Multiplexer 3 (net store).
- Splitter 7 connects to ROM alu control (net alu_addr), 8 bits wide.
- Splitter 7 connects to Splitter 8 (net b30).
- ROM alu control connects to Multiplexer 5 (net alu_sel), 8 bits wide.
- Decoder 1 connects to Register x1 (net we1).
- Decoder 1 connects to Register x2 (net we2).
- Decoder 1 connects to Register x3 (net we3).
- Decoder 1 connects to Register x4 (net we4).
- Decoder 1 connects to Register x5 (net we5).
- Decoder 1 connects to Register x6 (net we6).
- Decoder 1 connects to Register x7 (net we7).
- Decoder 1 connects to Register x8 (net we8).
- Decoder 1 connects to Register x9 (net we9).
- Decoder 1 connects to Register x10 (net we10).
- Decoder 1 connects to Register x11 (net we11).
- Decoder 1 connects to Register x12 (net we12).
- Decoder 1 connects to Register x13 (net we13).
- Decoder 1 connects to Register x14 (net we14).
- Decoder 1 connects to Register x15 (net we15).
- Decoder 1 connects to Register x16 (net we16).
- Decoder 1 connects to Register x17 (net we17).
- Decoder 1 connects to Register x18 (net we18).
- Decoder 1 connects to Register x19 (net we19).
- Decoder 1 connects to Register x20 (net we20).
- Decoder 1 connects to Register x21 (net we21).
- Decoder 1 connects to Register x22 (net we22).
- Decoder 1 connects to Register x23 (net we23).
- Decoder 1 connects to Register x24 (net we24).
- Decoder 1 connects to Register x25 (net we25).
- Decoder 1 connects to Register x26 (net we26).
- Decoder 1 connects to Register x27 (net we27).
- Decoder 1 connects to Register x28 (net we28).
- Decoder 1 connects to Register x29 (net we29).
- Decoder 1 connects to Register x30 (net we30).
- Decoder 1 connects to Register x31 (net we31).
- Decoder 1 connects to Splitter 9 (net rd_sel), 5 bits wide.
- Register x1 connects to Multiplexer 1, Multiplexer 2 (net x1), 32 bits wide.
- Register x1 connects to Register x2, Register x3, Register x4, Register x5, Register x6, Register x7, Register x8, Register x9, Register x10, Register x11, Register x12, Register x13, Register x14, Register x15, Register x16, Register x17, Register x18, Register x19, Register x20, Register x21, Register x22, Register x23, Register x24, Register x25, Register x26, Register x27, Register x28, Register x29, Register x30, Register x31, Multiplexer 6 (net wb), 32 bits wide.
- Register x2 connects to Multiplexer 1, Multiplexer 2 (net x2), 32 bits wide.
- Register x3 connects to Multiplexer 1, Multiplexer 2 (net x3), 32 bits wide.
- Register x4 connects to Multiplexer 1, Multiplexer 2 (net x4), 32 bits wide.
- Register x5 connects to Multiplexer 1, Multiplexer 2 (net x5), 32 bits wide.
- Register x6 connects to Multiplexer 1, Multiplexer 2 (net x6), 32 bits wide.
- Register x7 connects to Multiplexer 1, Multiplexer 2 (net x7), 32 bits wide.
- Register x8 connects to Multiplexer 1, Multiplexer 2 (net x8), 32 bits wide.
- Register x9 connects to Multiplexer 1, Multiplexer 2 (net x9), 32 bits wide.
- Register x10 connects to Multiplexer 1, Multiplexer 2, Output pin a0 (net x10, a0), 32 bits wide.
- Register x11 connects to Multiplexer 1, Multiplexer 2, Output pin a1 (net x11, a1), 32 bits wide.
- Register x12 connects to Multiplexer 1, Multiplexer 2 (net x12), 32 bits wide.
- Register x13 connects to Multiplexer 1, Multiplexer 2 (net x13), 32 bits wide.
- Register x14 connects to Multiplexer 1, Multiplexer 2 (net x14), 32 bits wide.
- Register x15 connects to Multiplexer 1, Multiplexer 2 (net x15), 32 bits wide.
- Register x16 connects to Multiplexer 1, Multiplexer 2 (net x16), 32 bits wide.
- Register x17 connects to Multiplexer 1, Multiplexer 2 (net x17), 32 bits wide.
- Register x18 connects to Multiplexer 1, Multiplexer 2 (net x18), 32 bits wide.
- Register x19 connects to Multiplexer 1, Multiplexer 2 (net x19), 32 bits wide.
- Register x20 connects to Multiplexer 1, Multiplexer 2 (net x20), 32 bits wide.
- Register x21 connects to Multiplexer 1, Multiplexer 2 (net x21), 32 bits wide.
- Register x22 connects to Multiplexer 1, Multiplexer 2 (net x22), 32 bits wide.
- Register x23 connects to Multiplexer 1, Multiplexer 2 (net x23), 32 bits wide.
- Register x24 connects to Multiplexer 1, Multiplexer 2 (net x24), 32 bits wide.
- Register x25 connects to Multiplexer 1, Multiplexer 2 (net x25), 32 bits wide.
- Register x26 connects to Multiplexer 1, Multiplexer 2 (net x26), 32 bits wide.
- Register x27 connects to Multiplexer 1, Multiplexer 2 (net x27), 32 bits wide.
- Register x28 connects to Multiplexer 1, Multiplexer 2 (net x28), 32 bits wide.
- Register x29 connects to Multiplexer 1, Multiplexer 2 (net x29), 32 bits wide.
- Register x30 connects to Multiplexer 1, Multiplexer 2 (net x30), 32 bits wide.
- Register x31 connects to Multiplexer 1, Multiplexer 2 (net x31), 32 bits wide.
- Multiplexer 1 connects to Adder 2, Subtractor 1, AND Gate 1, OR Gate 1, Comparator 1, Comparator 2 (net rs1_val), 32 bits wide.
- Multiplexer 2 connects to Multiplexer 4, RAM data, Comparator 2 (net rs2_val), 32 bits wide.
- Multiplexer 3 connects to Multiplexer 4 (net imm), 32 bits wide.
- Multiplexer 4 connects to Adder 2, Subtractor 1, AND Gate 1, OR Gate 1, Comparator 1 (net opb), 32 bits wide.
- Adder 2 connects to Multiplexer 5 (net r_add), 32 bits wide.
- Subtractor 1 connects to Multiplexer 5 (net r_sub), 32 bits wide.
- AND Gate 1 connects to Multiplexer 5 (net r_and), 32 bits wide.
- OR Gate 1 connects to Multiplexer 5 (net r_or), 32 bits wide.
- Comparator 1 connects to Bit Extender 4 (net lt), 8 bits wide.
- Bit Extender 4 connects to Multiplexer 5 (net r_slt), 32 bits wide.
- Multiplexer 5 connects to Splitter 10, Multiplexer 6 (net alu_out), 32 bits wide.
- Splitter 10 connects to RAM data (net daddr), 8 bits wide.
- RAM data connects to Multiplexer 6 (net mem_out), 32 bits wide.
- RAM data connects to Constant 6.
- Comparator 2 connects to AND Gate 2 (net eq).
- AND Gate 2 connects to Multiplexer 7 (net take).
- Adder 3 connects to Multiplexer 7 (net pc_br), 32 bits wide.
- Constant 7 connects to Comparator 3 (net c63), 32 bits wide.
- Comparator 3 connects to OR Gate 2 (net h1).
- Comparator 4 connects to OR Gate 2 (net h2).
- OR Gate 2 connects to Output pin halt (net halt).
Run two test programs
The first program adds 1 to 10 into a0, stores it to memory and loads it into a1.
addr instruction note
0x00 addi x5, x0, 10 counter
0x04 addi x10, x0, 0 sum = 0
0x08 add x10, x10, x5 loop: sum += counter
0x0c addi x5, x5, -1
0x10 beq x5, x0, +8 leave when 0
0x14 beq x0, x0, -12 back to the loop
0x18 sw x10, 0(x0) store the sum
0x1c lw x11, 0(x0) load it into a1
0x20 beq x0, x0, 0 halt
java -jar logisim-evolution-5.0.0-all.jar --tty table circ-mips-risc-v-cpu-rv32mini-sum.circ
(12 rows; a0 then a1, binary. The last row:)
0000 0000 0000 0000 0000 0000 0011 0111 0000 0000 0000 0000 0000 0000 0011 0111
The last row is 55 (0x37) in both columns. The second program tests the logic instructions:
addi x5, x0, 12 x5 = 12
addi x6, x0, 10 x6 = 10
and x10, x5, x6 8
or x11, x5, x6 14
sub x7, x6, x5 -2
slt x12, x7, x6 1 (-2 < 10)
slt x13, x6, x7 0
add x10, x10, x12 9
sw x7, 4(x0)
lw x11, 4(x0) 0xFFFFFFFE
beq x0, x0, 0 halt
Download sum and logic, with their program images rv32mini-sum.hex.txt and rv32mini-logic.hex.txt. Both circuits are 5.0.0 files.
Load a program from the command line
The instruction ROM is labelled imem, so a program image loads from the command line:
java -jar logisim-evolution-5.0.0-all.jar --tty table circ-mips-risc-v-cpu-rv32mini-sum.circ --load rv32mini-logic.hex.txt imem
With the logic image on the sum circuit, the output was the logic program’s rows. The image format is v3.0 hex words plain, one 32-bit word per line (memory image formats); the command-line options are on the command line page.
Check the encodings with an assembler
Hand-encoded instruction words are easy to get wrong, so check them with a real assembler. We wrote the same two programs in assembly and built them with LLVM’s llvm-mc for riscv32 with the M extension, then extracted the .text bytes. The nine words of the sum program and the eleven of the logic program matched our hex images exactly (F134). The same tool is a quick way to produce an image for your own core.
llvm-mc -triple=riscv32 -mattr=+m -filetype=obj sum.s -o sum.o
llvm-objcopy -O binary --only-section=.text sum.o sum.bin
The built-in RISC V IM component
The System On a Chip library holds a RISC V IM simulator, a SoC bus simulator and a Memory simulator. They are not wired together with wires. Each of the CPU and the memory has a Connected bus attribute: click it and pick the bus by its label. Before that, both show a red “Not connected to a bus”; afterwards the label turns green and shows the bus name. The CPU draws the 32 registers with their ABI names, a pc field and a trace panel, and has a Reset vector (0x0 by default) and a Sim state field that starts at Halted. The memory defaults to start address 0x0 and 1 kB.
Not tested
We did not run our core in the window, did not run any program on the built-in RV32IM or on a community project (the RV32I project we looked at has no output pins, so a headless run prints nothing to compare; F136), and did not build a pipelined design. Our core has no jumps, no byte or half-word loads and no multiply.
Common mistakes
- Registers 8 bits wide. A Register without its Data Bits attribute is 8 bits wide, so a 32-bit design shows U values.
- A component sitting on top of the clock. We once placed a constant at the same point as the Clock; the registers never saw an edge and the run printed one row.
- A branch offset with bit 0. The B immediate’s bit 0 is always 0.
- Word addresses. The memories are indexed by address bits 9 to 2; use word-aligned addresses.
A design like this could be exported as HDL (VHDL and Verilog) and mapped to a board (FPGA guide); we did not try that with this core. For a smaller CPU first, see the 8-bit CPU; registers are covered on the register page and all projects lists the rest.