This page is about My4TH. My4TH (pronounced "my fourth") is my fourth homebuilt
CPU-less computer after MyCPU, MyNOR and TraNOR. I wanted to build the simplest computer
possible, with a discrete CPU using as few gates and components as possible, running
a Forth operating system.
FORTH is an early programming language developed by Charles H. Moore in the late 1960s.
Moore developed FORTH on an IBM 1130 minicomputer, which had a 16-bit CPU and only 8 KB of RAM.
To keep things simple and reduce memory consumption, he implemented FORTH as a stack-based
virtual machine using the Reverse Polish Notation (RPN). But FORTH is much more than just
a programming language. Because FORTH has a built-in interpreter, compiler and disk
I/O support, a computer running FORTH is also called a "Forth system". My4TH is such
a Forth system. You can develop and debug your Forth programs directly on My4TH.
You can enter your source code with the built-in text editor and store it in the on-board
EEPROM memory. From there you can compile and run it directly on the My4TH board.
My4TH is based on MyNOR, so it also has a very simple 1-bit NOR gate "ALU".
Because of the simplicity of the hardware, My4TH cannot interpret Forth code directly.
Instead, it implements an interpreter written in native machine code.
To further increase execution speed, My4TH compiles Forth code into machine code
("Subroutine Threaded Code") rather than into intermediate byte code.
My4TH hardware features:
- 8-bit discrete logic CPU
- 8 to 14 MHz clock frequency
- 32 KB ROM, 32 KB RAM
- up to 256 KB EEPROM
- 1-bit NOR gate "ALU"
- 6300 8-bit additions / sec
- 4 memory chips
- 16 CMOS logic chips
- RS-232 with 4800 baud
- I2C-bus for extensions
- 6 digital inputs
- 5 digital outputs
- PCB size 10 x 10 cm
My4TH software features:
- 16-bit Forth system
- Supports the Forth 2012 standard
- Core and core extension words
- Double number word set
- Block word set
- Integrated text editor
This is the world's smallest*
Forth computer with the fewest components and a discrete CPU:
This computer is fully functional, but it has no support for the Block words. It consists of:
One 32 KB RAM, one 32 KB EPROM, 16 CMOS logic ICs, one oscillator,
four 100nF capacitors, one 150K resistor and two 10K resistor networks.
The wires come from a
FTDI USB->RS232 converter cable, which also supplies +5V to the computer.
The computer is controlled by a VT100 compatible serial terminal. After switching on,
My4TH displays a welcome message and the Forth prompt. Now you can immediately start
entering your own Forth program:
This is the block diagram of the My4TH computer. As you can see, there is
no CPU or microcontroller, just memory chips and simple CMOS logic chips:
Now look at the picture below. You will see all the blocks from the diagram above:
But one question remains: How does it all work?
It all starts with the microcode address counter, which is something like the "heart"
of the computer. Each machine instruction is composed of up to 128 microinstructions, whereby
a microinstruction consists of two parts: an 8-bit control word and an optional 8-bit data word.
The machine instruction (the "OP code") to be executed is applied to address lines
A8 to A14 of the EPROM, and the microcode address counter is connected to A0 to A7.
The microcode address counter counts through all microinstructions of the current OP code.
In every "even" clock cycle (when A0 is zero),
the first part of the microinstruction, namely the control word, is stored in the control word latch.
5 of the 8 signals of this control word are used to control the data flow through the processor by selecting
the source and destination device. The final data transfer occurs in the following "odd" clock
cycle when A0 is one. Since in this second clock cycle the EPROM itself can also serve as a data source,
it is easy to store constant values defined by the microcode in the various registers and the RAM.
However, since any address can be input into the EPROM in this cycle, it is possible to perform random read
accesses to the EPROM so that the application program (the Forth interpreter) can be executed from the EPROM.
As you can see, the main purpose of all the logic is to transfer data from the various sources to the
various destinations under the control of the microcode. The CPU registers such as PC, SP, Accu, etc. are all
stored in RAM. The programme counter is incremented via a look-up table in the EPROM.
Data manipulation is done via a single NOR gate on the D0 data line. You may already know that
really any logical function can be derived from the NOR function, even complex functions like
addition and subtraction. But to process all the bits of a byte, My4TH must loop over all the
data bits and process bit by bit. The required data shift function is also implemented as a
look-up table in the EPROM.
Conditional jumps are only possible within the 128 microcode positions of an OP code. When the
microcode needs to perform a conditional jump, it first loads the target address (which ranges
from 0 to 127) into the lower 8 bits of the 16-bit address latch. A control signal coming from the
control word latch then enables the conditional loading of the new address into the
microinstruction counter depending on the value of D0 within the odd clock cycle.
If you are more interested in the microcode, I recommend to study the document
"The MyNOR ADD instruction"
where I describe how
I implemented the ADD instruction in the microcode for the MyNOR computer. Since MyNOR and
My4TH are very similar, the microcode of the ADD function works exactly the same on My4TH.
But to increase performance, I cheated a little on the My4TH by implementing the one-bit adder
via a small look-up table in the EPROM.
Now we get down to business: The schematic. Click on the image to download it as a better readable PDF file.
Bill of material:
|Reference||Value || ||Reference||Value|
|C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 ||100 nF|| ||U1 ||74HC 74|
|D1||BAT41 || ||U2 U3 ||74HC 161|
|J1 ||D-SUB-09 male connector || ||U4 ||74HC 541|
|J2 ||Header 1x8 pin, 2.54mm || ||U5 U6 U7 U10 U17 U18||74HC 574|
|J3 ||Header 2x10 pin, 2.54mm || ||U8 ||74HC 14|
|J4 ||USB type B mini connector || ||U9 ||74HC 08|
|Q1 ||BC547B || ||U11 ||74HC 02|
|Q2 ||BS170 || ||U12 ||74HC 273|
|R1 R2 ||8x 10 kOhm array || ||U13 ||74HC 138|
|R3 ||2.2 kOhm || ||U14 ||74HC 139|
|R4 R5 ||10 kOhm || ||U15 ||AT27C256-70 (EPROM)|
|R6 ||150 kOhm || ||U16 ||AS6C62256-55 (SRAM)|
|SW1 ||push button || ||U19 U20 ||24LC1026-I/P (EEPROM)|
|X1 ||Oscillator 8.000 MHz || ||Socket ||PDIP-28 for U15|
Want to build your own? All you need is available for download.
Don't want to hunt for all the components yourself?
Buy a My4TH kit at Budgetronics!
Starting up My4TH and increasing the clock frequency
When you have finished assembling your own My4TH computer board, you can perform a first test.
For this test connect a LED to pins 2(+) and 5(-) of the RS-232 socket and connect the contacts
SCL and RXD of J2 with a wire jumper. After applying the supply voltage, the LED should blink.
The blinking frequency of the LED is 1 Hz when My4TH is clocked by an 8 MHz oscillator.
Note: This LED blinking test is very useful if you want to test the maximum clock
frequency My4TH can still work with. For example, if you have programmed the EPROM with the
image for 8 MHz operation, you will not be able to establish a RS-232 connection if you clock
My4TH with 10 MHz, because the baud rate has the unusual value of 6000 baud. In this case the
LED can give you a first hint if My4TH can be operated with this higher frequency.
As a second step, you can now burn an EPROM with the image intended for 10 MHz operation.
If you have access to My4TH via the serial terminal, you can use the following one-liner
to test if My4TH works stably with the new frequency. The line outputs a simple maze
consisting of random / and \ characters:
: test begin 2 random if 47 else 92 then emit again ; test
Support for Adafruit STEMMA QT and SparkFun Qwiic boards
My4TH provides an I2C interface for connecting external devices. I decided to support the
Adafruit STEMMA QT and SparkFun Qwiic interface standards because the STEMMA QT boards are
designed to operate at 5V and many SparkFun Qwiic boards are also suitable for 5V operation.
As you can see on the picture, there is a very easy way to equip the My4TH
board with the STEMMA QT / Qwiic connectors.
If you take a closer look at J2, you will recognize the STEMMA QT and Qwiic pin order:
SCL, SDA, +5V and GND. This makes it easy to connect the
SparkFun Qwiic Adapter Board.|
I have written some sample "screens" to show how to use some of the Adafruit boards.
You can find the source code in the software section of this website.
Need more information?
If you are missing something, please check the menu at the top of this page.
Here are some direct links for your convenience:
- The ForthDeck is described on a separate page: ForthDeck.
- A collection of Forth programs for My4TH can be found in the software section.
- If you are interested in Forth and how I have implemented it, look here: Forth on My4TH
- If you still have unanswered questions: Check out the FAQ.
- Looking for schematics and source code? You can get them in the download section.
The cross assembler "myca" is licensed under the
GNU General Public License, Version 3.