What you will build
LDV-8 has 8-bit data, 8-bit addresses, 12-bit instructions and 16 instructions. It is single-cycle: every instruction finishes in one clock cycle. It is a Harvard design: the program lives in one ROM and the data in a separate RAM. Time: about 8 to 12 hours over several sessions. You should have built the adders and the ALU and know registers, the RAM and the ROM.
Describe this circuit
Components: Clock 1; Input pin reset; Register pc reg; Adder 1; Constant 1; Constant 2; Multiplexer 1; ROM prog; Splitter 1; ROM ctrl; Splitter 2; NOT Gate 1; AND Gate 1; AND Gate 2; AND Gate 3; AND Gate 4; AND Gate 5; AND Gate 6; OR Gate 1; Register acc reg; Register flags reg; Register out reg; RAM data; Constant 3; Multiplexer 2; Adder 2; Constant 4; NOT Gate 2; Adder 3; Constant 5; AND Gate 7; OR Gate 2; XOR Gate 1; Shifter 1; Shifter 2; Constant 6; Multiplexer 3; Splitter 3; Splitter 4; Splitter 5; Splitter 6; Splitter 7; XNOR Gate 1; XOR Gate 2; AND Gate 8; XOR Gate 3; XOR Gate 4; AND Gate 9; Multiplexer 4; Constant 7; Constant 8; Constant 9; Constant 10; Multiplexer 5; Constant 11; Constant 12; Constant 13; Constant 14; Constant 15; Constant 16; Comparator 1; Constant 17; Splitter 8; Splitter 9; Splitter 10; Hex Digit Display 1; Hex Digit Display 2; LED 1; Output pin out; Output pin halt; Output pin pc; Output pin acc.
- Clock 1 connects to Register pc reg, Register acc reg, Register flags reg, Register out reg, RAM data (net clk).
- Input pin reset connects to Register pc reg, Register acc reg, Register flags reg, Register out reg (net reset).
- Register pc reg connects to Adder 1, ROM prog, Output pin pc (net pc), 8 bits wide.
- Register pc reg connects to Multiplexer 1 (net pc_next), 8 bits wide.
- Register pc reg connects to NOT Gate 1, AND Gate 1, AND Gate 2, AND Gate 3, AND Gate 4 (net run).
- Adder 1 connects to Constant 1 (net one), 8 bits wide.
- Adder 1 connects to Multiplexer 1 (net pc_inc), 8 bits wide.
- Adder 1 connects to Constant 2, Adder 2, Constant 4 (net zero).
- Multiplexer 1 connects to Splitter 1, RAM data, Multiplexer 2 (net operand), 8 bits wide.
- Multiplexer 1 connects to OR Gate 1 (net jump).
- ROM prog connects to Splitter 1 (net instr), 12 bits wide.
- Splitter 1 connects to ROM ctrl (net op), 8 bits wide.
- ROM ctrl connects to Splitter 2 (net cw), 12 bits wide.
- Splitter 2 connects to AND Gate 1 (net acc_we).
- Splitter 2 connects to AND Gate 2 (net flags_we).
- Splitter 2 connects to AND Gate 3 (net mem_we).
- Splitter 2 connects to Multiplexer 2 (net bsel).
- Splitter 2 connects to Multiplexer 3, Multiplexer 4, Multiplexer 5 (net alu_f), 3 bits wide.
- Splitter 2 connects to OR Gate 1 (net jmp).
- Splitter 2 connects to AND Gate 5 (net jz).
- Splitter 2 connects to AND Gate 6 (net jc).
- Splitter 2 connects to AND Gate 4 (net out_we).
- Splitter 2 connects to NOT Gate 1, LED 1, Output pin halt (net halt).
- AND Gate 1 connects to Register acc reg (net acc_we_e).
- AND Gate 2 connects to Register flags reg (net flags_we_e).
- AND Gate 3 connects to RAM data (net mem_we_e).
- AND Gate 4 connects to Register out reg (net out_we_e).
- AND Gate 5 connects to OR Gate 1 (net jz_hit).
- AND Gate 5 connects to Splitter 9 (net z).
- AND Gate 6 connects to OR Gate 1 (net jc_hit).
- AND Gate 6 connects to Splitter 9 (net c).
- Register acc reg connects to Register out reg, RAM data, Adder 2, Adder 3, AND Gate 7, OR Gate 2, XOR Gate 1, Shifter 1, Shifter 2, Splitter 3, Output pin acc (net acc), 8 bits wide.
- Register acc reg connects to Multiplexer 3, Splitter 7, Comparator 1 (net alu_r), 8 bits wide.
- Register flags reg connects to Splitter 9 (net flags), 4 bits wide.
- Register flags reg connects to Splitter 8 (net flags_in), 4 bits wide.
- Register out reg connects to Splitter 10, Output pin out (net out), 8 bits wide.
- RAM data connects to Multiplexer 2 (net ram_q), 8 bits wide.
- RAM data connects to Constant 3.
- Multiplexer 2 connects to Adder 2, NOT Gate 2, AND Gate 7, OR Gate 2, XOR Gate 1, Multiplexer 3, Splitter 4 (net b), 8 bits wide.
- Adder 2 connects to Multiplexer 3, Splitter 5 (net r_add), 8 bits wide.
- Adder 2 connects to Multiplexer 4 (net c_add).
- NOT Gate 2 connects to Adder 3 (net nb), 8 bits wide.
- Adder 3 connects to Multiplexer 3, Splitter 6 (net r_sub), 8 bits wide.
- Adder 3 connects to Constant 5 (net one1).
- Adder 3 connects to Multiplexer 4 (net c_sub).
- AND Gate 7 connects to Multiplexer 3 (net r_and), 8 bits wide.
- OR Gate 2 connects to Multiplexer 3 (net r_or), 8 bits wide.
- XOR Gate 1 connects to Multiplexer 3 (net r_xor), 8 bits wide.
- Shifter 1 connects to Shifter 2, Constant 6 (net s1), 3 bits wide.
- Shifter 1 connects to Multiplexer 3 (net r_shl), 8 bits wide.
- Shifter 2 connects to Multiplexer 3 (net r_shr), 8 bits wide.
- Splitter 3 connects to Multiplexer 4 (net acc0).
- Splitter 3 connects to XNOR Gate 1, XOR Gate 2, XOR Gate 3, XOR Gate 4, Multiplexer 4 (net acc7).
- Splitter 4 connects to XNOR Gate 1, XOR Gate 3 (net b7).
- Splitter 5 connects to XOR Gate 2 (net radd7).
- Splitter 6 connects to XOR Gate 4 (net rsub7).
- Splitter 7 connects to Splitter 8 (net r7).
- XNOR Gate 1 connects to AND Gate 8 (net same_a).
- XOR Gate 2 connects to AND Gate 8 (net chg_a).
- AND Gate 8 connects to Multiplexer 5 (net v_add).
- XOR Gate 3 connects to AND Gate 9 (net diff).
- XOR Gate 4 connects to AND Gate 9 (net chg_s).
- AND Gate 9 connects to Multiplexer 5 (net v_sub).
- Multiplexer 4 connects to Constant 7.
- Multiplexer 4 connects to Constant 8.
- Multiplexer 4 connects to Constant 9.
- Multiplexer 4 connects to Constant 10.
- Multiplexer 4 connects to Splitter 8 (net c_new).
- Multiplexer 5 connects to Constant 11.
- Multiplexer 5 connects to Constant 12.
- Multiplexer 5 connects to Constant 13.
- Multiplexer 5 connects to Constant 14.
- Multiplexer 5 connects to Constant 15.
- Multiplexer 5 connects to Constant 16.
- Multiplexer 5 connects to Splitter 8 (net v_new).
- Comparator 1 connects to Constant 17 (net zero8), 8 bits wide.
- Comparator 1 connects to Splitter 8 (net z_new).
- Splitter 10 connects to Hex Digit Display 2 (net lo), 4 bits wide.
- Splitter 10 connects to Hex Digit Display 1 (net hi), 4 bits wide.
All files are saved in the 5.0.0 format and verified there. There is no classic 2.7.1 version: sequential test vectors need Evolution, and the command-line behaviour we rely on differs in 2.7.1 (F04, F05).
Part 1: The instruction set
Registers and memory: ACC (8 bits), PC (8 bits), four flags Z, N, C and V, an output register OUT (8 bits), a program ROM of 256 words of 12 bits and a data RAM of 256 bytes. An instruction is 12 bits: the opcode is bits 11 to 8 and the operand is bits 7 to 0. In hex the first digit is the opcode and the last two digits are the operand, so D05 is JZ to address 05.
| 0 | HLT | none | Stop: nothing changes any more and halt is 1 | none |
|---|---|---|---|---|
| 1 | LDA a | address | ACC gets RAM[a] | Z N (C V cleared) |
| 2 | LDI n | 8-bit value | ACC gets n | Z N (C V cleared) |
| 3 | STA a | address | RAM[a] gets ACC | none |
| 4 | ADD a | address | ACC gets ACC + RAM[a] | Z N C V |
| 5 | SUB a | address | ACC gets ACC - RAM[a] | Z N C V |
| 6 | ADI n | 8-bit value | ACC gets ACC + n (ADI FF subtracts 1) | Z N C V |
| 7 | AND a | address | ACC gets ACC AND RAM[a] | Z N (C V cleared) |
| 8 | OR a | address | ACC gets ACC OR RAM[a] | Z N (C V cleared) |
| 9 | XOR a | address | ACC gets ACC XOR RAM[a] | Z N (C V cleared) |
| A | SHL | none | ACC shifted left by 1 | Z N C (old bit 7) |
| B | SHR | none | ACC shifted right by 1 | Z N C (old bit 0) |
| C | JMP a | address | PC gets a | none |
| D | JZ a | address | if Z = 1 then PC gets a | none |
| E | JC a | address | if C = 1 then PC gets a | none |
| F | OUT | none | OUT gets ACC | none |
No rows match.
Opcode 0 is HLT on purpose: an empty ROM, or a program image that failed to load, reads as all zeros and stops the CPU at once instead of running wild. There is no subtract-immediate because ADI FF adds 255, which subtracts 1 in two’s complement. After SUB, a carry means the first number was at least the second (unsigned), so JC after SUB means “greater or equal”.
Part 2: Program counter
The PC holds the address of the current instruction. Its next value is PC + 1 or a jump target. Build it from an 8-bit Register (clear from reset, enable from en), an Adder that adds the constant 1, and a 2-input Multiplexer with 8 data bits that chooses between PC + 1 and target. The adder’s carry-in is tied to 0.
Download circ-8-bit-cpu-pc.circ and its vector. The 39-row sequential vector with CLK as an input pin counts 0 to 5, jumps to 0x80, counts on, holds with en at 0 and resets (test vectors). It passed.
Part 3: Program memory and fetch
Add a ROM with Address Bit Width 8 and Data Bit Width 12 and give it the label prog: the label is what --load targets later (F16). Its contents are saved inside the .circ (F12). A splitter turns the 12-bit word into op (bits 11 to 8) and operand (bits 7 to 0); set each bit’s end explicitly in the splitter’s attributes (splitter).
Download circ-8-bit-cpu-fetch.circ and its vector (28 rows, passed). It has the countdown program stored and checks op and operand on the first cycles: 2 and 05, F and 00, D and 05, 6 and FF, C and 01.
Part 4: ALU, accumulator and flags
LDV-8’s ALU is built from Logisim’s own Adder, gates and Shifters rather than imported from the 4-bit project. Its operation input alu_f selects through an 8-input multiplexer:
| 0 | add |
|---|---|
| 1 | subtract |
| 2 | and |
| 3 | or |
| 4 | xor |
| 5 | shift left |
| 6 | shift right |
| 7 | pass B |
No rows match.
Input B is a 2-input multiplexer: RAM data (bsel 0) or the operand (bsel 1). Subtract is ACC + NOT B + 1 on a second adder, so its carry means “no borrow”. Overflow for add is “A and B have the same sign and the result’s sign differs from A”; for subtract it is “A and B differ and the result’s sign differs from A”. Z comes from a comparator against 0, N is the result’s top bit, and C is the adder carry, or the bit shifted out for shifts. The ACC, FLAGS (4 bits) and OUT registers share the clock and write only when their enable is 1.
The data RAM has 8 address bits and 8 data bits, address from operand, data in from ACC, store from mem_we, load tied to 1.
Download circ-8-bit-cpu-datapath.circ and its vector. In it you play the control unit: the control signals are input pins, and the vector runs LDI, ADI, STA, LDA, OUT, SUB, SHL, SHR, AND, OR and XOR instructions and checks ACC, FLAGS and OUT after each clock (55 rows, passed).
Part 5: Control unit
The control word is 12 bits, one bit per signal: bit 0 acc_we, 1 flags_we, 2 mem_we, 3 bsel, bits 4 to 6 alu_f, 7 jmp, 8 jz, 9 jc, 10 out_we, 11 halt. A 16 by 12 ROM labelled ctrl holds one word per opcode, so the table below is the hardware:
| 0 | HLT | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 800 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | LDA a | 1 | 1 | 0 | 0 | 7 | 0 | 0 | 0 | 0 | 0 | 073 |
| 2 | LDI n | 1 | 1 | 0 | 1 | 7 | 0 | 0 | 0 | 0 | 0 | 07B |
| 3 | STA a | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 004 |
| 4 | ADD a | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 003 |
| 5 | SUB a | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 013 |
| 6 | ADI n | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 00B |
| 7 | AND a | 1 | 1 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 023 |
| 8 | OR a | 1 | 1 | 0 | 0 | 3 | 0 | 0 | 0 | 0 | 0 | 033 |
| 9 | XOR a | 1 | 1 | 0 | 0 | 4 | 0 | 0 | 0 | 0 | 0 | 043 |
| A | SHL | 1 | 1 | 0 | 0 | 5 | 0 | 0 | 0 | 0 | 0 | 053 |
| B | SHR | 1 | 1 | 0 | 0 | 6 | 0 | 0 | 0 | 0 | 0 | 063 |
| C | JMP a | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 080 |
| D | JZ a | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 100 |
| E | JC a | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 200 |
| F | OUT | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 400 |
No rows match.
The jump signal is jmp OR (jz AND Z) OR (jc AND C), using the flags stored by the previous instruction. Every write enable (PC, ACC, FLAGS, RAM, OUT) is ANDed with NOT halt; the clock itself keeps running. A decoder with OR gates would also work (decoder); we used a ROM because the table is the design.
Download circ-8-bit-cpu-control.circ, its vector (22 rows, passed) and the control ROM image.
Part 6: Put it together
Wire the blocks: one clock for every register and the RAM; reset to the clear of PC, ACC, FLAGS and OUT; RAM address and jump target from operand; halt as an output pin labelled exactly halt; out as an 8-bit output pin from the OUT register. The main circuit has a Clock component, a reset input, output pins out, halt, pc and acc, two Hex Digit Displays on OUT (displays) and an LED on halt.
Download circ-8-bit-cpu-ldv8.circ (countdown stored in prog). The first cycles of the countdown, before each clock edge:
| 0 | 00 | 205 | 00 | 0 0 | 00 |
|---|---|---|---|---|---|
| 1 | 01 | F00 | 05 | 0 0 | 00 |
| 2 | 02 | D05 | 05 | 0 0 | 05 |
| 3 | 03 | 6FF | 05 | 0 0 | 05 |
| 4 | 04 | C01 | 04 | 0 1 | 05 |
| 5 | 01 | F00 | 04 | 0 1 | 05 |
| 6 | 02 | D05 | 04 | 0 1 | 04 |
No rows match.
Show values as a table
| cycle | PC | ACC | OUT |
|---|---|---|---|
| 0 | 00 | 00 | 00 |
| 1 | 01 | 05 | 00 |
| 2 | 02 | 05 | 05 |
| 3 | 03 | 05 | 05 |
| 4 | 04 | 04 | 05 |
| 5 | 01 | 04 | 05 |
| 6 | 02 | 04 | 04 |
We did not capture a timing diagram from the window, so this waveform is the model’s, and the test of the circuit itself is the line-by-line match of its output.
Step through a program
The values below were recorded from our reference model, which matched Logisim's own output (out, pc and acc) on every cycle of all three programs. Nothing here simulates a circuit.
- 00 205 LDI 05
- 01 F00 OUT
- 02 D05 JZ 05
- 03 6FF ADI FF
- 04 C01 JMP 01
- 05 000 HLT
| PC | 00 |
|---|---|
| Instruction | 205 |
| ACC | 00 (0) |
| Z N C V | 0 0 0 0 |
| OUT | 00 (0) |
| ALU | pass B |
| Signals | acc_we, flags_we, bsel |
Part 7: Write your first programs
A listing line is an address, a hex word and a mnemonic. To hand-assemble, write the opcode digit and then the two-digit operand. Three programs, each with a listing and an image in v2.0 raw:
- countdown
205 F00 D05 6FF C01 000: outputs 5, 4, 3, 2, 1, 0, then halts after 23 instructions. Listing, image. - sum (1 + 2 + … + 10 using RAM at 0x80 and 0x81): outputs 55 (0x37); halts after 85 instructions. Listing, image.
- fibonacci (until the next number would not fit in 8 bits, using JC): outputs 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 and halts after 117 instructions. Listing, image.
Keep your data in RAM from 0x80 up, end with HLT, and remember the RAM is 0 after reset. Exercises with no solutions here: multiply by repeated addition, the larger of two numbers with SUB and JC, count the 1 bits with SHR and JC, output the even numbers, swap two RAM bytes.
Part 8: Load programs with a memory image
Make an image with the memory image generator: Data Bits 12, Address Bits 8, format v2.0 raw. The countdown image is two lines:
v2.0 raw
205 f00 d05 6ff c01 0
In the window, right-click the prog ROM and choose Load Image, then reset the simulation (Ctrl+R) and turn on ticks (Ctrl+K). After opening any file, click the canvas or press Ctrl+R before judging whether wires are right (F45). Contents loaded into a ROM can be saved in the file (F12). We did not capture the Load Image dialog for LDV-8.
On the command line:
java -jar logisim-evolution-5.0.0-all.jar --tty table circ-8-bit-cpu-ldv8.circ --load ldv8-countdown.txt prog
Output: 0000 0000 0000 0000 0000 0000
Output: 0000 0000 0000 0001 0000 0101
Output: 0000 0101 0000 0010 0000 0101
Output: …
Output: 0000 0000 0000 0101 0000 0000
exit: 0
The three programs were run this way and their output matched the reference model on every line (F111). Each line is one clock cycle: the three columns are out, pc and acc, and the run stops by itself when halt is 1. The installers’ launchers take the same options (F28).
Part 9: Run, watch and measure
In the window, enable ticks with Simulate, Auto-Tick Enabled (Ctrl+K) and watch the Hex Digit Displays count down and the halt LED light (clock and simulation). To step, use Manual Tick Half Cycle (Ctrl+T) or Full Cycle (Ctrl+F9). We have no step screenshots of LDV-8 in the window.
On the command line --tty table prints one row per clock cycle until halt, in binary. See the command line reference for halt, speed and the other formats. --tty speed on the countdown printed 5000 Hz (45 ticks in 9 milliseconds); the run is too short to be a speed measure, so we give no performance claim.
Common mistakes
| LDA loads the old value | The RAM's Asynchronous read is No. Set it to Yes. | Tested (F111) |
|---|---|---|
| --load seems to do nothing | The circuit must come first, and the circuit needs a halt pin when you use --tty table. | Tested (F13, F16, F111) |
| The CPU halts at once after loading | The image was rejected (no header line) and the ROM is empty, so address 0 reads as HLT. | Tested for the rejection (F15) |
| The CPU never stops on the command line | There is no output pin labelled exactly halt in the circuit that runs. | Not reproduced here |
| Nothing happens after loading | Ticks are off, or the simulation was not reset; click the canvas or press Ctrl+R. | Seen for grey wires (F45) |
| PC adds 2 per clock, or RAM writes every clock | The clock goes through logic, or the store input is not driven by mem_we. | Not reproduced here |
No rows match.
Extensions
A shared bus like a breadboard CPU needs tri-state drivers (controlled buffer) and several clock steps per instruction. Input from a keyboard: not published here. A 16-bit CPU needs wider ROM and registers. Running LDV-8 on an FPGA: see the FPGA guide; HDL-only generation stops until every input and output is mapped and saved (F51), and we have not run LDV-8 on a board or checked which of its parts export to HDL.
Downloads
Circuits: pc, fetch, datapath, control, ldv8. Images and listings: countdown, sum, fibonacci, control ROM. Not built: the two broken examples the plan lists. All files are CC BY 4.0 and 5.0.0 only. Back to projects.
To combine the parts into one file for submission, merge them as described in libraries, merging and copying circuits.