---
created_at: '2016-06-05T06:52:53.000Z'
title: The J1 Forth CPU (2010)
url: http://excamera.com/sphinx/fpga-j1.html
author: panic
points: 64
story_text: 
comment_text: 
num_comments: 54
story_id: 
story_title: 
story_url: 
parent_id: 
created_at_i: 1465109573
_tags:
- story
- author_panic
- story_11839943
objectID: '11839943'

---
[Source](http://excamera.com/sphinx/fpga-j1.html "Permalink to The J1 Forth CPU &mdash; excamera")

# The J1 Forth CPU &mdash; excamera

# The J1 Forth CPU[¶][1]

![_images/timing.jpg][2]

(Here is the [J1 paper][3] I presented at [EuroForth 2010][4]).

Note

Own a J1! The [_Gameduino: a game adapter for microcontrollers_][5] features a sporty 50 MHz J1 CPU. [_Available here_][6].

J1 is a small ([200 lines][7] of Verilog) stack-based CPU, intended for FPGAs. A complete J1 with 16Kbytes of RAM fits easily on a small Xilinx FPGA. Some highlights:

> * Extremely high code density. A complete system including the TCP/IP stack fits in under 8K bytes.
> * Single cycle call, zero cycle return
> * Instruction set maps trivially to Forth
> * Cross compiler runs on Windows, Mac and Unix
> * Basic software includes a sizeable subset of [ANS Forth][8] and a portable TCP/IP networking stack.

J1 was originally designed to run the six [WGE100 Ethernet cameras][9] in the [Willow Garage PR2 robot][10].

More recently it was shown at [SVFIG Forth Day 2010][11] on an [XESS FPGA board][12] (see [_Loading the XESS XSA-3S1000 from Python_][13]) running a few demonstration programs, including space invaders, Forth source [invaders.fs][14].

![_images/invaders.jpg][15] ![_images/closeup.jpg][16]

The code is at [j1demo.tar.gz][17].

## About the J1[¶][18]

The J1 is a simple 16-bit CPU. It has some RAM, a program counter (PC), a data stack and a call/return stack. It has a small set of built-in arithmetic instructions. Fields in the J1 instructions control the arithmetic function, and write the results back to the data stacks. There are more details on instruction coding in the [paper][3].

The J1 is probably close to the simplest possible useful CPU.

## Forth on the J1[¶][19]

The CPU was designed to run Forth programs very efficiently: the machine’s instructions are so close to Forth that there is little benefit to writing code in assembler. Effectively Forth _is_ the assembly language. J1 runs at about 100 Forth MIPS on a typical FPGA. This compares with about 0.1 Forth MIPS for a traditional threaded Forth running on an embedded 8-bit CPU.

To build the j1 binary `j1.bin` with gforth, do:
    
    
    $ cd j1demo/firmware
    $ make j1.bin
    

The code that defines the basic Forth operations as J1 instructions is in [basewords.fs][20]

The next layer up defines basic operations in terms of these simple words. These include many of the CORE words from the DPANS94 Forth standard. Some of the general facilities provided by [nuc.fs][21]

> * byte memory access
> * string handling
> * double precision (i.e. 32 bit) math
> * one’s complement addition
> * memory copy and fill
> * multiplication and division, fractional arithmetic
> * pictured numeric output
> * debug words: memory and stack dump, assert

The above files - about 2K of code - bring the J1 to the point where it can start to define application-specific code.

## The TCP/IP Stack[¶][22]

### Ethernet driver[¶][23]

The Ethernet driver is responsible for packet reception and transmission. This component deals with the various supported pieces of [MAC][24] hardware above.

Supported hardware for the Ethernet driver:

> * The Microchip ENC28J60
> * The open source MAC used in the PR2’s cameras
> * The AX88796 used in the XESS development board [eth-ax88796.fs][25]

### Network components[¶][26]

ARP
: Address Resolution Protocol. The ARP module maintains a small cache of ARP network addresses, and responds to ARP queries for our Ethernet address. [arp.fs][27]

IP
: Internet Protocol. The ip module constructs the IP header. [ip.fs][28]

UDP
: User Datagram Protocol packet construction. [udp.fs][29]

DHCP
: Optional DHCP client implementation. This allows the network device to get its IP address automatically. [dhcp.fs][30]

NTP
: Optional Network Time Protocol client. [ntp.fs][31]

DNS
: Optional Domain Name System client. [dns.fs][32]

More [_VHDL, Verilog and FPGA notes_][33].

[ ![Logo][34] ][35]

### Quick search

Enter search termKLAKKKs or a module, class or function name. 

© Copyright 2009-2015 James Bowman. Created using [Sphinx][36] 1.2b1. 

[1]: http://excamera.com#the-j1-forth-cpu "Permalink to this headline"
[2]: http://excamera.com/_images/timing.jpg
[3]: http://excamera.com/files/j1.pdf
[4]: http://www.complang.tuwien.ac.at/anton/euroforth/ef10/
[5]: http://excamera.com/gameduino/index.html#gameduino
[6]: http://excamera.com/gameduino/distributors.html#distributors
[7]: http://excamera.com/files/j1demo/verilog/j1.v
[8]: http://forth.sourceforge.net/std/dpans/
[9]: http://www.ros.org/wiki/wge100_camera_firmware
[10]: http://www.willowgarage.com/pages/pr2/overview
[11]: http://forth.org/svfig/kk/11-2010.html
[12]: http://www.xess.com/prods/prod039.php
[13]: http://excamera.com/fpga-xess-python.html#xess-lpt
[14]: http://excamera.com/files/j1demo/docforth/invaders.fs.html
[15]: http://excamera.com/_images/invaders.jpg
[16]: http://excamera.com/_images/closeup.jpg
[17]: http://excamera.com/files/j1demo.tar.gz
[18]: http://excamera.com#about-the-j1 "Permalink to this headline"
[19]: http://excamera.com#forth-on-the-j1 "Permalink to this headline"
[20]: http://excamera.com/files/j1demo/docforth/basewords.fs.html
[21]: http://excamera.com/files/j1demo/docforth/nuc.fs.html
[22]: http://excamera.com#the-tcp-ip-stack "Permalink to this headline"
[23]: http://excamera.com#ethernet-driver "Permalink to this headline"
[24]: http://en.wikipedia.org/wiki/Media_Access_Control
[25]: http://excamera.com/files/j1demo/docforth/eth-ax88796.fs.html
[26]: http://excamera.com#network-components "Permalink to this headline"
[27]: http://excamera.com/files/j1demo/docforth/arp.fs.html
[28]: http://excamera.com/files/j1demo/docforth/ip.fs.html
[29]: http://excamera.com/files/j1demo/docforth/udp.fs.html
[30]: http://excamera.com/files/j1demo/docforth/dhcp.fs.html
[31]: http://excamera.com/files/j1demo/docforth/ntp.fs.html
[32]: http://excamera.com/files/j1demo/docforth/dns.fs.html
[33]: http://excamera.com/fpga-vhdl-verilog.html#main
[34]: http://excamera.com/_static/minilogo.png
[35]: http://excamera.com/sphinx/fpga-vhdl-verilog.html
[36]: http://sphinx.pocoo.org/

