nandgatehdl
extremely small logic blocks of computer architecture
overview
I want to assemble all the basic parts of the computer architecture from NAND.
But I want to ignore the details related to electricity and
just think about the logical structure.
For this purpose, I made a script execution environment that only outputs
the status of a specified location every clock.
So, there is only logical NAND here.
1. a simple example
The first step was to figure out how to describe the structure of the following figure.

The explanation for each is as follows.
- The numbered rows in the figure are the terminals (ports) that connect each element.
LO
always sends out a 0
signal.
HI
always sends out a 1
signal.
LED
displays the received signal on the screen.
So, if the diagram is correct, the LED will display the value NAND(0,1) => 1
.
I write this as follows.
LO 1000
HI 1001
LED 3000
NAND 0001 0002 0003
CONNECT 1000 0001
CONNECT 1001 0002
CONNECT 0003 3000
Save it to a text file 01.txt
and try to run it.
It doesn't stop, so stop it with Ctrl+C
.
$ nandgatehdl.exe 01.txt
000000: 3000=[1]
----
000001: 3000=[1]
----
000002: 3000=[1]
----
The 000000:
, 000001:
, 000002:
, and so on, displayed on the left side of the screen
show the elapsed time of the clock. If nothing is specified, one clock ticks per second.
The 3000=[1]
on the right is the result. The 3000
is the port number of the LED,
and the [x]
is the value. It returns 1
.
2. another example
Here is an example of XOR.

The following are some additional points that were not covered in the previous explanation.
- The port number is a string of numbers from
0
to 9
. There are no reserved numbers.
- Each line can be in any order.
I write XOR as follows.
HI 1111
HI 2222
LED 3333
CONNECT 0012 3333
NAND 0001 0002 0003
CONNECT 1111 0001
CONNECT 2222 0002
NAND 0004 0005 0006
CONNECT 1111 0004
CONNECT 0003 0005
NAND 0007 0008 0009
CONNECT 2222 0007
CONNECT 0003 0008
NAND 0010 0011 0012
CONNECT 0006 0010
CONNECT 0009 0011
Save it to a text file 02.txt
and try to run it.
It doesn't stop, so stop it with Ctrl+C
.
$ nandgatehdl.exe 02.txt
000000: 3333=[0]
----
000001: 3333=[0]
----
000002: 3333=[0]
----
It should be XOR(1,1) => 0
.
If you check the port numbers 1111
and 2222
four ways
with LO
and HI
, you will see that the result is XOR.
Except for the comment format, the port number is specified after the reserved word.
As mentioned earlier, the port number can be any string of characters between 0
and 9
.
There are no reserved numbers.
Action |
Format |
Note |
Add NAND |
NAND input1 input2 output |
#1 |
Connect port to port |
CONNECT from to |
#2 |
Define a port that always returns 0 |
LO output |
#1 |
Define a port that always returns 1 |
HI output |
#1 |
Define a port that returns clock |
CLOCK output |
#1 |
Define a port to monitor the results |
LED input |
#1 |
Add comment |
// this is comment |
|
Note |
Explanation |
#1 |
Port numbers should not overlap with existing ones. |
#2 |
At least one of the port numbers must be an existing one. |
All of them except CONNECT
require you to specify a new port number.
The following specification is not possible.
// NG
LO 1
HI 2
NAND 1 2 3
LED 3
It needs to be written as follows.
// OK
LO 1
HI 2
NAND 3 4 5
CONNECT 1 3
CONNECT 2 4
LED 6
CONNECT 5 6
4. latch
There are a number of things that surprised me when I was learning something,
but LATCH is one of them.
This simple structure of a latch can "continue" the previous output.

The input/output of this configuration is as follows.
Input A |
Input B |
Output |
LO |
LO |
don't use |
LO |
HI |
HI |
HI |
LO |
LO |
HI |
HI |
Same value as current Output |
As for the "don't use", it means that this simulator, without any electrical considerations, will not work as expected.
This means that it will not work as expected.
This configuration is described like this. Let A
be LO
and B
be HI
.
LO 0001
HI 0002
LED 0003
NAND 0004 0005 0006
NAND 0007 0008 0009
CONNECT 0001 0004
CONNECT 0002 0007
CONNECT 0006 0008
CONNECT 0009 0005
CONNECT 0006 0003
Save it to a text file 04.txt
and try to run it.
It doesn't stop, so stop it with Ctrl+C
.
$ nandgatehdl.exe 04.txt
000000: 0003=[1]
----
000001: 0003=[1]
----
000002: 0003=[1]
----
If we check A
and B
in reverse, we can see that the results are as shown in the table.
5. d-latch