"Coding - the language hidden behind computer hardware and software" refinement - Chapter 15-16 (Hexadecimal, RAM)

"Learning is like a seedling that springs up. If you don't see it increase, it will grow day by day." ——Zhu Xi of Song Dynasty

hexadecimal

Hex overview

Hexadecimal is a base system suitable for computers. In decimal, the weight of the previous digit is ten times that of the latter digit, for example, the value of 288 is:

288=2* 102+8* 101+8*100

In hexadecimal, the weight of the previous digit is sixteen times that of the latter digit. If you want to indicate that the number is in hexadecimal, you can add h after it, for example, 288h means 288 in hexadecimal (beginners may not understand here, the h here only means that the number is in hexadecimal, not placeholder). The value of 288h is:

288h=2* 16 2 +8* 16 1 +8*16 0 =648 (decimal)

hexadecimal table

Please add a picture description

byte to hex

A byte is eight binary bits, and a byte is converted into hexadecimal by four or four, and the conversion from the eight-bit binary number represented by the byte to hexadecimal is completed. for example:

  1. Convert 11011001 to hexadecimal.
    insert image description here
  2. Four four separates this byte.
    insert image description here
  3. Computes the left and right hexadecimal values ​​separately.
    insert image description here
  4. Combine the left and right results to get the final result is B9.

It can be verified that the result on both sides of the equation is 185.

Summary: For hexadecimal conversion, as long as the weight of each bit in hexadecimal is 16 times different, decimal and binary are similar. For the conversion directly involved in decimal, such as converting from binary to decimal, you only need to divide or multiply the corresponding weight; if the conversion is not directly involved in decimal, such as converting from binary to hexadecimal, then Generally, the decimal system is used as a bridge for conversion.

memory

In the previous eight-bit latch, we have realized the core function of data storage, but a complete memory also needs specific read and write functions.

Let's first review the structure of the 8-bit latch, that is, 8 1-bit latches:
insert image description here
Obviously, at the input end, we need to implement the write function for a specific latch, and at the output end we need to implement the write function for a specific lock memory read function.

specific read function

Let's implement a relatively simple read function first. The read function is realized through the 8-1 selector. The following is the circuit of this selector:
insert image description here
the lower left corner uses three switches to select 8 gates, using the principle that three binary bits can form 8 different numbers. The three control terminals and one data terminal are connected to the AND gate. In the AND gate, as long as one of the three control terminal inputs is 0, the output result must be 0, so the final data output is only ANDed with the one whose control terminal is all 1. It is related to the data terminal received by the gate. for example:

  1. If the input terminals are 010 respectively, the control terminal inputs at the eight AND gates are 101, 001, 111, 011, 100,000, 110, 010 respectively; it is not difficult to see that only the output results of the D 2 AND gates depend on Data terminal, the rest of the output must be 0.
  2. The outputs of these eight AND gates are connected to the rightmost OR gate. Since the outputs of the other seven AND gates are all 0, the result of the output terminal depends on the output result of the D 2 AND gate, that is, depends on the data terminal D 2 .

If you don't understand this circuit, you can give an example and follow this step again.

specific write function

The write function is to implement the function of inputting a data into a specific latch. So the input can only have one switch. This is easy to solve, just use a switch to connect eight inputs. The function of selecting a specific input can also be used with the circuit above. The circuit constructed in this way is called a 3-8 decoder, and the circuit diagram is as follows:
insert image description here
The idea of ​​this circuit is basically the same as above, so there is no need to explain it with examples.

RAM

The circuit we finally got is as follows:
insert image description here
This circuit can realize reading, writing (addressing) and storage of specific locations. It's called Random Access Memory (RAM). The notation is as follows:
insert image description here
Three switches are here represented as addresses.

large RAM array

8-bit RAM can be connected in two ways.

  1. The two RAMs share addresses.
    insert image description here
    This connection can store eight numbers, and the bit width of each number is 2 bits, which is equivalent to an 8x2 RAM.
  2. On the basis of the above, a 1-2 decoder and a 2-1 selector are added, which can only be input to one bit of one of the two registers at a time, and a 16x1RAM effect is constructed.
    insert image description here
    The rightmost select terminal here is actually the fourth address. Therefore, 4 addresses can mark 16 numbers. (The bit width here is not fixed, because the first circuit can be used to expand the bit width).

One of the above two circuits can increase the number of stored numbers, and the other can expand the bit width limit of the stored numbers. Therefore, we can build a large RAM array as follows:
insert image description here
This RAM array stores 8KB.
Please add a picture description
I am Frost_Ai, a newcomer working hard on the road of algorithms, thank you for reading! If you think it is good, you can pay attention to it, and I will bring more and more comprehensive knowledge explanations in the future!

Guess you like

Origin blog.csdn.net/m0_72987309/article/details/130461221