Skip to main content

4 Bit TTL CPU

·663 words·4 mins
Table of Contents

A TTL CPU I built a long time ago when I bought a huge stock of NOS TTL chips on ebay

Details
#

4 Bit TTL CPU
#

A few years ago I purchased a large quantity of old LS-TTL chips in an internet auction. Wanting to put them to use, I started to design a CPU around them.

I decided to go with a 4 bit datapath to reduce the circuit size. The CPU uses separated program and data memory, a Harvard architecture. The width of the program memory is 8-bit. A side effect is, that there is no way to write to the program memory. This forbids self-modifying code and renders constructs like subroutines very difficult. The data memory consists of 32 4-bit “registers”. All operations are performed on a single accumulator. Actually, the general idea behind the architecture can be very well compared to the Microchip PIC. See below for an instruction reference.

The CPU circuit was designed on paper and built on three veroboards. It is difficult to believe, but the circuit worked on the first power up. A few photos of this mess are displayed at the bottom of this page.

Registers
#

RegisterBitsDescription
PC11:0Program counter
Accu3:0Accumulator
r00-r153:016 Work registers
r16-r233:08 I/O registers
r24-r313:0Scratchpad
Flags:C-Carry/Borrow
Flags:Z-Zero flag

Instruction list
#

SymbolMeaning
rregister
iimmediate value
aaddress
AcAccumulator
r16[r0..r15]
r32[r0..r32]
imm4[0 .. 15]
add12[0 .. 4095]
MnemonicMachine codeLengthCyclesFlagsOperation
ADC r160011 rrrr11ZCAc=Ac+r16+C
ADC #imm40111 iiii11ZCAc=Ac+imm4+C
OR r160001 rrrr11Z-Ac=Ac OR r16
AND r160000 rrrr11Z-Ac=Ac AND r16
XOR r160010 rrrr11Z-Ac=Ac XOR r16
XOR #imm40110 iiii11Z-Ac=Ac XOR imm4
LDI #imm40100 iiii11Z-Ac=imm4
STA r32110r rrrr11r32=Ac
LDA r32111r rrrr11Z-Ax=r32
SEC0101 100011-CC=1
CLC0101 000011-CC=0
ROL0101 110011ZCAc=(Ac«1)+Cold, Cnew=Accu Bit 3
LSL0101 010011ZCAc=Ac«1, Cnew=Accu Bit 3
NOP0110 000011does nothing. (in fact it executes Ac=Ac XOR 00)
JCS $add121000 aaaa aaaa aaaa22Jump if C=1
JCC $add121001 aaaa aaaa aaaa22Jump if C=0
JMP $add121010 aaaa aaaa aaaa22Jump always
JNZ $add121011 aaaa aaaa aaaa22Jump if Z=0

Images
#

ALU-Board component and solder side. This boards holds the ALU, registerfile, accumulator, flags and some bus muxes. The ALU consists of a 4 bit boolean function unit (8x LS00 to the right), a 4 bit adder (LS283), 4 bit XOR (LS86) and the result multiplexer/shifter (2x LS153). The registerfile is a simple single port 256x4 sram (Harris 6561). The two LS175 hold the accumulator and the flags. The black components to the left contain various status LEDs.

Program/Control component and solder side. Holds the program ROM, the program counter logic and various instruction decoding. The program counter logic consists of the PC (3x LS193), branch logic (LS 175 and more ?) and a branch adress register (LS373,LS175). The GAL and 4x LS00 are used as instruction decoder. The GAL replaces around 8-10 ICs of random logic, so it is really put to good use.

PLL board, component side. This board generates the required two phase clock signal. In addition it allows single step clocking for debug purposes. The clock frequency can be adjusted between fractions and multiples of a MHz, using the DIP switches and the jumpers. The two phase clock and lots of extra trouble could probably have been avoided by spending additional thought on the design.

(c) 2002 Tim - Last change: 16 October 2002

Exported from Hackaday.io 4 Bit TTL CPU