Graphic | Do you call this broken thing a computer?

Xiaoyu and I fall in love early, and we live next door.

1. Coding and circuit-signal conversion

At night, the parents would confiscated the mobile phone, but we still wanted to continue chatting, but we didn't dare to make a sound, so we thought of this way...

We use the combination of on and off of the light bulb to represent all Chinese, and at the same time, we agreed to read the status of the light bulb every second and record it. This is our secret code.

Me : bright and off

Hi : off bright off bright off

Huan : bright off bright off bright

You : bright bright bright off

In this way, even though we don't have a mobile phone, we can still chat day by day. Although the efficiency is low, we are still very happy.

In this way, Xiaoyu and I inadvertently converted the language into a light bulb combination. This process is called coding .

Second, the gate circuit-signal correlation

Just like this, Xiaoyu and I kept talking in secret until we went to college and our parents could no longer control our mobile phones.

But after so many years of talking with small light bulbs, we always feel that things are not that simple, so we started some new explorations.

We have added a switch. At this time, when the two switches are closed at the same time, the bulb will light up.

In this way, there is no longer the simple correspondence between the two switches and the light bulb, but logic .

The opening and closing of the switch correspond to the opening and connection of the circuit respectively. The non-lighting and lighting of the small light bulb also correspond to the disconnection and connection of the circuit respectively. Then the two can be unified, and no longer rely on specific physical performance.

Also, the connection and disconnection of the switch is active. The connection and disconnection of the small light bulb is passive and a result.

We call the connection and disconnection of the switch here as the input terminal , and the connection and disconnection of the bulb as the output terminal , and encapsulate the entire circuit in a figure, we can get the following abstraction:

We decided to call this circuit a gate circuit , and the above one is called an AND gate

In order to explore more abstractly in the future, we will express the circuit connection as the number 1, and the circuit disconnection as the number 0.

We call this representation binary .

Type A

Type B

Output

0

0

0

0

1

0

1

0

0

1

1

1

Slowly, we discovered more and more ways to play.

The above circuit, I abstracted it into the following gate circuit shape, called the OR gate .

After that, it was out of control. Xiaoyu and I designed more and more gate circuits. We found that as long as it is a logical relationship we can think of, it can be designed into a corresponding gate circuit.

Three, adder-signal calculation

Decimal numbers can be converted into binary numbers, and binary numbers can correspond to the input and output of the gate circuit.

So Xiaoyu and I had a bold idea, can we design a circuit that calculates addition?

We start with the simplest one-bit binary number addition:

0+0=0;0+1=1;1+0=1;1+1=10

Into a table as follows

Addend A

Addend B

And adding outputs an

Carry out

0

0

0

0

0

1

1

0

1

0

1

0

1

1

0

1

That is, we need to design a circuit that can achieve the input and output effects in the table.

After unremitting efforts, it was finally discovered that this circuit can be composed of two gate circuits, an exclusive OR gate and an AND gate .

This device implements one-bit addition in binary, but it is not perfect because it only considers the carry output of these two numbers, but does not consider the carry of the previous one, so it can only be called a half adder .

If you take the previous carry into account, you only need to add one more half adder and splice one OR gate.

At this point, we have built a perfect one-bit adder and proudly call it a full adder .

After the full adder is made, no matter how many adders are can be made, just put the full adders together one by one. Let's try to make an eight-bit adder .

OK, you're done, with the adder, you can theoretically implement any mathematical operation.

Because we know that multiplication can be converted into addition, division can be converted into subtraction, and subtraction can be converted into addition of complement. Now we can proudly call this component, the arithmetic logic unit ALU .

 

Fourth, the clock-the oscillation of the signal

Xiaoyu and I are very happy, and finally realized the calculation function by way of circuit.

But slowly I felt that it was not interesting, so we came up with a whim and designed the following weird circuit.

When switch A is closed, the whole circuit is connected, switch B will be sucked down, the whole circuit is disconnected, the electromagnet loses its magnetism, switch B will bounce up, the circuit is connected again, and switch B is sucked down again.

In this way, the switch B continuously and quickly cycled between opening and closing, and we have never interfered with this circuit, so the circuit has the characteristic of self-feedback .

Due to the back and forth oscillation of switch B, we call this kind of circuit an oscillator . Because it can generate a constantly changing electrical signal that runs constantly and regularly like a clock, we call this device a clock . The alternating electrical signal it produces is called a clock signal .

Five, RAM-save the signal

Although there is an adder, where do the input numbers come from? Can it be stored somewhere first?

After many experiments, Xiaoyu and I invented a very complicated circuit:

If the input terminal is 1, the signal of "a certain control terminal" is changed (the moment the signal changes from 0 to 1), the output terminal becomes 1, and the output terminal still maintains (stores) the just 1.

If the input terminal is 0, change the "a certain control terminal" signal, the output terminal becomes 0, and then the output terminal still maintains (stores) the just 0.

It doesn't matter if you don't understand it, just remember the design of this circuit and realize the storage function of one bit! We call it a  1-bit latch .

Then we combine multiple latches, plus some 3-8 decoders, 8-1 selectors and other circuits, we can realize a memory that can store 8-bit binary, and can read and write it randomly. We call it  RAM , or memory for short .

This component can be combined again to form an N × M RAM array. For example, we can represent a 1024 * 8 RAM array.

This means that the storage capacity is 1024 units, and each unit occupies 8 bits.

For more convenient representation, we specify 1024 = 1K, 8 bits = 1 byte (8 bit = 1 byte), then we can say that the storage capacity of this RAM is 1K units, and each unit occupies 1B. In other words, the address space is 1K, and the storage capacity is 1KB. 

At this point, this RAM module is almost perfect, and we can even use it alone to store data in a certain address and read out the data in a certain address.

How is it convenient for people to operate? You only need to connect the address input, data input, and write operation terminals to a control panel . The switch controls whether the input of these signals is 1 or 0. Then connect the data output to some light bulbs for easy observation. A storage device that can be manually operated, and that's it.

With readable and writable memory, we can store several numbers in the memory in advance. Next, can we let the arithmetic logic unit ALU  automatically read this number and perform addition operations?

6. Procedure-Automation

Let's introduce a new component, a 10-bit counter , where Clk is connected to the clock signal we talked about in the fourth part, and Clr is the clear terminal. The specific effect is clear in the animation below.

The output of the counter is 0, 1, 2, 3, 4, 5, which can be used as an address in memory .

We connect this counter, as well as the ALU and RAM mentioned above, to try to implement a device that can accumulate and sum .

What we want to calculate is 1+2+3+4+5+6+7, this is how this automated calculator works

1. Use the control panel to store the numbers 1~7 in RAM address 0~6, which has been realized in the previous section.

2. When the value of the counter is 0, data 1 is output to the adder for calculation. At this time, the adder A=1, B=0, and the calculation result is 1, but remember that the latch stores the last addition The output of the device is 0, and the calculation result of this time has to wait for the next latch to encounter the rising edge signal.

3. When the value of the counter is 1, data 2 is input to the adder. At this time, the latch stores the last calculation result 1, and outputs this 1 to the light bulb, and at the same time returns to the B of the adder , So at this time the adder A=2, B=1, the calculation result is 3

4. When the value of the counter is 3, and so on, please see the figure below 

We have automated the process of cumulative summation ! Afterwards, if you want to calculate the cumulative sum, just use the control panel to store the data in the memory in advance! Is it convenient?

Seven, program instructions

We also want more automation!

At present, this device can only accumulate the data in RAM from beginning to end without thinking, and cannot choose which to add or not to add, nor can it choose when to stop.

For example, the data in our RAM is like this.

Address (hexadecimal)

Data (decimal)

0x00

...

0x01

10

0x02

...

0x03

20

0x04

30

0x05

...

...

...

We only want to accumulate the data at the blue address of RAM, ignore the data at other places, and stop at RAM 0x05. What should we do?

We can add another RAM. The data stored in this RAM represents the meaning of " instructions "!

We first invent three kinds of instructions.

add : Accumulate the value at this location in RAM

nop : Ignore the value here (that is, do nothing)

halt : stop (increase the value of the counter) 

In order to achieve the above functions, the data in the corresponding instruction RAM should be like this.

Note: There is a one-to-one correspondence between the address of the instruction RAM below and the address of the data RAM above!

address

(Hexadecimal)

Instruction RAM value

 

Command meaning

0x00

nop

do nothing

0x01

add

Accumulate

0x02

nop

do nothing

0x03

add

Accumulate

0x04

add

Accumulate

0x05

halt

stop

...

...

...

We need to introduce a control unit and place it in the following position.

When encountering the nop instruction (0x00), the output will disable the W bit of the latch, and the write operation of the latch is not allowed, so the accumulation result will not be entered.

For another example, when the input is a halt instruction (0x05), the EN bit of the counter is disabled, and the counter +1 is not allowed, so that the stop effect is achieved.

At this time, let the clock signal oscillate to achieve a selective summation process and hover at the specified position. Now let's make the clock signal vibrate and take a look at this process. (Only key components are left here) 

How should this control unit be implemented? We know that any component can be made as long as input is given and output is given. This article will no longer expand. 

With three instructions, we know that all operations can be automated in this way, with various complex controllers.

The next thing we need to do is to design the controller and agree on a lot of instructions so that through the arrangement and combination of this lot of instructions, any automated calculation operation can be realized. 

We will design a lot of instructions

Referred to as a set of instructions

Functions that we can achieve after permuting and combining instructions

Called program

We combine this process of permutation and combination of instructions

Called programming

We will arrange the people who combine these instructions

Called programmer

And what will we call the device that will carry all of this?

That's right, this shit is

meter

Calculate

machine

postscript

This article is inspired by a masterpiece of computer science, "Coding | Language Hidden Behind Computer Software and Hardware". I would like to pay tribute to this book.

I extracted the core ideas and wrote a low-concurrency style article for readers. If you are very confused about the overall principles of computers, I hope this article can give you a little bit of confusion. At the same time, I hope you can find time to read the entire book. I promise you will be very rewarding.

The core purpose of this article and this book is to let you understand the thinking of computers. In fact, computer instructions and data are all stored in memory. Other places in the article are also simplified models of computers. It is said that the computer is a broken gadget, especially it is not allowed to say that this is a low-concurrency programming SWFW tells you~

Guess you like

Origin blog.csdn.net/coderising/article/details/113874691