Adder
The smallest custom IP example: a 32-bit hardware adder on an FPGA. You write two 32-bit numbers and
read back their sum, computed by the circuit, plus a carry bit when the sum does not fit in 32 bits.
Built with nanopynq. Nothing to install: in Chrome or Edge,
on this version's page, select your board, press Open the panel, then Write to the board,
Connect, and Open the notebook.
What is on the board
| IP | Address | What it is |
|---|
adder | 0x7000 | the 32-bit adder |
leds | 0x1000 | the six on-board LEDs |
buttons | 0x2000 | buttons S1 and S2 |
sys | 0x0 | design information |
The registers of adder (byte offsets):
| Offset | Name | Access | Meaning |
|---|
0x0 | a | rw | the first number |
0x4 | b | rw | the second number |
0x8 | sum | ro | a + b, the low 32 bits |
0xc | carry | ro | 1 when a + b does not fit in 32 bits |
Try it
The first cell of the notebook writes a=1, b=2 and shows ol.adder.register_map:
{'a': 1, 'b': 2, 'sum': 3, 'carry': 0}.
Add two numbers:
ol.adder.write(0x0, 3) # a
ol.adder.write(0x4, 4) # b
ol.adder.read(0x8) # sum: 7
Overflow:
ol.adder.write(0x0, 0xFFFFFFFF)
ol.adder.write(0x4, 2)
ol.adder.register_map # sum 1, carry 1
Check it against Python on random numbers:
import random
for _ in range(100):
a, b = random.getrandbits(32), random.getrandbits(32)
ol.adder.write(0x0, a)
ol.adder.write(0x4, b)
assert (ol.adder.read(0xc) << 32) | ol.adder.read(0x8) == a + b
"all 100 match"
From local Python with pip install "nanopynq[fabricgate]":
from nanopynq import Overlay
ol = Overlay("fabricgate://fabricgate/adder:1.0.0", board="tangnano9k") # or board="tangnano20k"
License
MIT License. Copyright (c) 2026 FabricGate Contributors.