Kits
›
How a CPU Counts
RU
EN
ES
Contents
Introduction
History: how machines learned to add
Lesson 1. Gates and the half adder: 1 + 1 = 10
1.1. The idea: adding one digit
1.2. Building
1.3. Check
Lesson 1 paste (Cmd+I)
Lesson 2. The full adder and 4 bits: the carry runs through the digits
2.1. The idea: column addition
2.2. Building
2.3. Check
Lesson 2 paste (Cmd+I)
Lesson 3. Negative numbers and subtraction: two's complement
3.1. The idea: numbers on a circle
3.2. Flags
3.3. Building
3.4. Check
Lesson 3 paste (Cmd+I)
Lesson 4. 8 bits and comparison: CMP is subtraction
4.1. The idea: two halves
4.2. The idea: comparison is subtraction
4.3. Building
4.4. Check
Lesson 4 paste (Cmd+I)
Lesson 5. The ± calculator: the minus on a lamp, the magnitude on the display
5.1. The idea: the magnitude is one more subtraction
5.2. Building
5.3. Check
Lesson 5 paste (Cmd+I)
Lesson 6 (bonus). Decimal math: add six
6.1. The idea: a digit in four bits
6.2. Why the display is in HEX mode
6.3. Building
How to set the digits
6.4. Check
Lesson 6 paste (Cmd+I)
Summary
All the parts
Instructions in pictures
Lesson 3 in pictures
← Back to the lesson: Lesson 3. Negative numbers and subtraction: two's complement
3
Subtraction and flags
two's complement, the SUB switch, lamps C Z N V
kh
HB-02
A
0
A3
0
A2
1
A1
1
A0
B
0
B3
1
B2
0
B1
1
B0
1
SUB
1110
S
C
Z
N
V
3 − 5 = −2
IN
10×
OUT
6×
XOR
6×
1
ADDER4
1×
2
AND
1×
1
0
9×
OR
2×
1
NOR
1×
1
4×
4b
0
A
3×
∞
Ctrl
+
G
ADDSUB4
© 2026 Daniil Khanin · khanin.info · HB-02
18
CANVAS
1
Delete
0
A0
0
A1
0
A2
0
A3
0
B0
0
B1
0
B2
0
B3
4b
DEC
A
2
Delete
4b
DEC
B
8b
DEC
S
3
Delete
ADDER4
A0
A0
A1
A1
A2
A2
A3
A3
B0
B0
B1
B1
B2
B2
B3
B3
CI
GND
S0
S0
S1
S1
S2
S2
S3
S3
CO
S4
© 2026 Daniil Khanin · khanin.info · HB-02
19
ADDSUB4
4
IN
10×
OUT
6×
A0
A1
A2
A3
B0
B1
B2
B3
SUB
CI
S0
S1
S2
S3
CO
V
5
XOR
3×
1
9×
XOR
I0
B0
I1
SUB
O0
bx0
XOR
I0
B1
I1
SUB
O0
bx1
XOR
I0
B2
I1
SUB
O0
bx2
6
XOR
1×
1
3×
XOR
I0
B3
I1
SUB
O0
bx3
7
ADDER4
1×
2
14×
ADDER4
A0
A0
A1
A1
A2
A2
A3
A3
B0
bx0
B1
bx1
B2
bx2
B3
bx3
CI
CI
S0
S0
S1
S1
S2
S2
S3
S3
CO
CO
© 2026 Daniil Khanin · khanin.info · HB-02
20
ADDSUB4 …
CANVAS
8
XOR
2×
1
AND
1×
1
9×
XOR
I0
A3
I1
S3
O0
va
XOR
I0
bx3
I1
S3
O0
vb
AND
I0
va
I1
vb
O0
V
9
Ctrl
+
G
Library
…
Chip N
2×
Library
…
ADDSUB4
Enter
ADDSUB4
A0
A1
A2
A3
B0
B1
B2
B3
SUB
CI
S0
S1
S2
S3
CO
V
10
0
5×
5×
0
A0
0
A1
0
A2
0
A3
0
B0
© 2026 Daniil Khanin · khanin.info · HB-02
21
CANVAS …
11
0
4×
4×
0
B1
0
B2
0
B3
0
SUB
12
ADDSUB4
1×
16×
ADDSUB4
A0
A0
A1
A1
A2
A2
A3
A3
B0
B0
B1
B1
B2
B2
B3
B3
SUB
SUB
CI
SUB
S0
S0
S1
S1
S2
S2
S3
S3
CO
C
V
V
13
OR
2×
1
NOR
1×
1
9×
OR
I0
S0
I1
S1
O0
z01
OR
I0
S2
I1
S3
O0
z23
NOR
I0
z01
I1
z23
O0
Z
© 2026 Daniil Khanin · khanin.info · HB-02
22
CANVAS …
14
4×
4×
C
Z
S3
V
15
4b
0
A
3×
4b
DEC
A
4b
DEC
B
4b
BIN
S
A
0
A3
0
A2
1
A1
1
A0
B
0
B3
1
B2
0
B1
1
B0
1
SUB
1110
S
C
Z
N
V
A
0
A3
1
A2
0
A1
1
A0
B
0
B3
1
B2
0
B1
1
B0
1
SUB
0000
S
C
Z
N
V
A
0
A3
1
A2
1
A1
1
A0
B
0
B3
0
B2
0
B1
1
B0
0
SUB
1000
S
C
Z
N
V
© 2026 Daniil Khanin · khanin.info · HB-02
23
← Back to the lesson
Lesson 3. Negative numbers and subtraction: two's complement