<<The mystery of coding>> Induction and summary

       The university went to <<The Principle of Microcomputer>>, <<Information Theory and Coding>>, <<Digital Circuit>>, <<The Principle and Technology of Single Chip Microcomputer>>. I have been unable to integrate these scattered knowledge into a whole, until I read <<The Mystery of Coding>>, I have a feeling of enlightenment.

1. What is Coding?
Coding or code in this book generally refers to a system that converts information between humans and machines. Language, writing and coding are all rules of communication. As long as we agree on the rules of use, we can communicate with each other
different codes, suitable for different occasions. For example, language cannot be stored on paper, so words are used; language and words are not suitable for transmitting messages quietly in the
dark . As long as one encoding can be used in situations where other encodings cannot, it is a useful encoding.

 

2. Why are binary codes used in computers?
The original computer was a mechanical product, one of which was an electromagnetic relay (as shown in the figure below). An electromagnetic relay can only represent two states. When the wire around the electromagnetic relay is energized, the magnet is attracted and the upper wire is connected. After the power is turned off, the iron ring loses its magnetism, and under the action of the spring, the magnet returns to its original position, so the circuit is disconnected again.


               
 

 

3. The relationship between Boolean algebra and logic

What is truth? Aristotle thought it had to do with logic. Aristotle's logic is based on the syllogism. The most famous syllogism is:
(All men are mortal; Socrates is man; therefore, Socrates is mortal.)
In a syllogism, two premises are assumed to be true, and a conclusion follows from it.

 

Mathematicians wrestled with Aristotle's theory of logic, trying to represent it with mathematical symbols and operators.

Boolean algebra provides a mathematical method for solving Aristotle's syllogisms. Look again at the two premises of this famous syllogism: 1. All men are mortal; 2. Socrates is a man.


We use the letter P for the set of all people, M for the set of things to die, and S for Socrates. So what does it mean that "all men are mortal"? It actually means that the intersection of the set of all people and the set of all dead things is the set of all people, that is:
P×M = P
and P×M = M This formula is wrong, because the dead things also include Cats, dogs, elms and more. And "Socrates is a man" means that the intersection of the set of Socrates (very small) and the set of all people (very large) is the set of Socrates:
S×P = S
Since from the first formula Knowing that P = P×M, we can substitute it into the second formula, namely:
S×(P×M) = S
According to the associative law, the above formula is equivalent to:
(S×P)×M = S
but we have Knowing that S×P is equal to S, the above formula can be simplified to:
S×M = S
Now the calculation is complete. This expression tells us that the intersection of Socrates and the set of all mortals is Socrates, which means that Socrates is mortal. Conversely, if S×M is considered equal to 0, then the conclusion is that Socrates cannot die. Furthermore, if S×M is equal to M, the conclusion that can be drawn is that Socrates is the only thing that dies, and everything else is immortal!  

 

 

4. How does computer hardware implement logical operations?

    Switches, electromagnetic relays, logic gates are all available.

 

      In the beginning, people used switches and circuits in series and parallel to perform logic operations, as shown in the following figure.

      

 

Later people replaced switches with electromagnetic relays, because relays can be controlled by other relays without having to use fingers.

As long as the electromagnetic relays are connected in a certain way, a logic gate circuit can be formed. An "AND" gate is shown in the following figure:

 



 

5. How to implement an adding machine?

Addition is the most basic arithmetic operation. So, if you want to build a computer, you must first know how to build a machine that can add two numbers together. When you solve this problem, you'll find that addition is the only thing computers do.

 

Compared with modern calculators and computers, the adding machine constructed in this chapter is large, cumbersome, slow, and noisy. But what's
interesting is that it's made up of all the electronics you've learned about in previous chapters, such as switches, light bulbs, wires, batteries, and
relays that make up several kinds of logic gates.

 

Let's first look at how 1-bit addition is implemented in hardware. Computers use binary, so the input is either 1 or 0. The following figure is a schematic diagram of a half adder, which can calculate the sum of 2 inputs

0+0=1, no carry

1+0=1, no carry

0+1=1, no carry

1+1=0, carry



 

Complex calculations cannot be solved with one half adder, so we thought of combining 8 half adders together, then more complex operations can be performed. The principle is that the carry output of the previous full adder is the carry input of the latter full adder . Each subsequent column number is concatenated in this way. The eighth bulb and the last pair of switches are connected to the last full adder as shown below: Here the last carry output is connected to the ninth bulb. In this way, 8 full adders are constructed successfully. As shown below:

 



 

 

6. How to construct a more complex 16-bit adding machine with an 8-bit adding machine?


 

 

7. How to use an adding machine to achieve subtraction?

According to the knowledge learned in the principle of microcomputer, the adding machine can complete the subtraction operation only by adding a circuit that seeks the complement. So, in the circuit, it is to add 8 inverters.


 

But this circuit negates all numbers, we only need to negate it when doing subtraction, so we need to improve it.
 



 
 

 

8. What is the principle of the trigger and what is the use?

The principle is shown in the figure below, the trigger can save information

 



 

 

. Closing the switch above will light the bulb, when disconnected again, the bulb will still be on.
. Close the switch below to turn off the light bulb, when disconnected again, the light bulb still does not light up.

 

According to the function of the flip-flop, we combine 8 flip-flops together to form an 8-bit latch



 

9. How to use the adding machine and latch to realize the accumulation function?



 

The output of the 8-bit adder is saved to the 8-bit latch, and then the output of the 8-bit latch is connected to the adder through the 2-1 selector, thus realizing the continuous operation.

 

10. Fundamentals of memory



 This kind of latch is RAM, which can write/read data. By integrating multiple such memories, a 64KB memory can be formed, as shown in the following figure:


 


 11. How to use the switch to operate the memory?

Utilizing the control panel to operate all memory—writing data to memory or verifying written data—would be more
advanced . This control panel uses 16 switches to represent the address, 8 switches to represent the 8-bit data that needs to be input into the memory, 8
bulbs 8-bit data, and one switch to represent the write signal, as shown in the figure below :



 12. How to connect the RAM memory to the accumulator?



 

In this way, we store the data that needs to be operated on the RAM memory first, then the calculation can be performed automatically.

There are 100 numbers added, we save the data to 0000H-0063H, through the control panel, the whole calculation process will run automatically.

 

 13. How to make the adder work automatically?

Suppose we want to add 3 numbers together first, then add the other 2 numbers, and finally add the other 3 numbers. The location of these 8 numbers in the memory is shown in the following figure:

To do an addition, you must first transfer a byte from memory to the accumulator. This operation is called a load . The second operation to perform is to add a byte from memory to the accumulator. The third item is to fetch the result from the accumulator and save it to memory. Finally, there needs to be some way to stop the automatic adder from working.

In detail, let the automatic adder do the following:
. Load the number at address 0 0 0 0 h into the accumulator. Add the number at
address 0 0 0 1 h into the accumulator
. Put Add the number at address 0 0 0 2h to the accumulator
. Store the number in the accumulator at address 0 0 0 3h
. Load the number at address 0 0 0 4h into the accumulator
. Put address 0 Add the number in 0 0 5h to the accumulator
. Save the number in the accumulator to address 0 0 0
6h. Load the number in the address 0 0 0 7h into the accumulator
. Put the number in the address 0 0 0 Add the number in 8h to the accumulator. Add the number in address
0009h to
the accumulator. Save the number in the accumulator to address 000Ah
. Stop the automatic adder
 

Sometimes we also want to directly load the number in the memory into the accumulator or save the number in the accumulator to the memory. After everything is done, we also want to stop the automatic adder to check the contents of the RAM array. How to accomplish these tasks?

 

The computer assembled in 12 can only execute the accumulation operation step by step. Now, in order to make the computer execute commands more flexibly, the 4 operations of the computer (load, add, stop, save) can be represented by the instruction code, so you can use 1 RAM to store instructions, 1 RAM to store data, as shown below:



 

 

However, this method of storing instructions and data separately has a flaw, and it is not allowed to use the previous calculation results in subsequent calculations , because the process executed by the previous automatic adder is that the code RAM array and the data RAM array are at the same time. 0000A starts addressing, and each instruction in the code RAM array corresponds to each data storage unit in the data RAM array. Once the instruction saves a certain number, it cannot be loaded into the accumulator again. As shown below:



 

Therefore, to do some changes, after improvement, each instruction occupies 3 bytes in memory, the first byte is the instruction, and the last two bytes store a 16-bit memory unit address. As shown below:




 After improvement, data and instructions can be stored on a RAM.

 

However, a new problem has arisen. If the computer fetches instructions sequentially, it will stop running at 000CH. If two new numbers are to be accumulated now, how to extract the data in 0010H-0013H?

We can retype new and more complex instructions, but you definitely don't want to do that. How to save trouble? Add a JUMP instruction to the instruction and replace the stop instruction with a jump instruction.

 

 

14. Contacts of switches, electromagnetic relays, tubes, transistors

The existence of these things is an entity that performs logical operations. The reason why the former is constantly replaced by the latter lies in cost, response speed, and integration.

 

15. What is a central processing unit (cpu)?

It is to integrate all the logic gate circuits, adders (ALU), control components, etc. mentioned above into one chip.

 

16. Why does the memory need to use the stack?

The working method of the stack is first-in, last-out, so that the track of the work can be saved in an orderly manner. After executing the high-priority task, it can return to the original task and continue to execute.

 

The stack is part of RAM.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326578187&siteId=291194637