How does the program work?

Summary: The computer's memory, all programs in the computer run in the memory, which is the memory of your computer. Computer memory is also called Random Access Memory, or RAM for short.

The memory is generally used to store program instructions and calculation data, and help the CPU to exchange data with external storage devices such as hard disks. The memory can only temporarily store program instructions and data. When the computer is turned off, the data in the memory will disappear. The program instructions or operating data in the computer are stored and calculated in the memory in the form of binary.

We can think of memory as a row of squares, and each square can store either 0 or 1.

Among them, a square is also called a bit, which divides 8 consecutive bits into a group, which represents 1 byte.

If the memory is compared to a building, then the bytes are the rooms in the building, and each room corresponds to a unique house number, so each byte has a unique address. Then these addresses are also called memory addresses . Through the memory address, we can access every byte in the memory. The memory address is generally expressed in hexadecimal, and the number expressed in hexadecimal starts with 0X. If the memory address is from eight 0 to eight F, the size of the memory is the eighth power of 16, which is 2^32. Bytes = 4GB in size.

Using the DEBUG program in Windows, you can simulate and view the CPU, registers, and related data in the memory. Here we use the DEBUG command to observe and understand the memory more intuitively. The observed data is not the real one in the current memory. data.

Then, in addition to using bytes as the unit to indicate the size of the memory, we can also use kilobytes KB, megabytes MB, and gigabytes GB. Generally speaking, today’s computers are all expressed in GB. Describe the size of the memory, where 1KB is equal to 1024 bytes, 1MB is equal to 1024KB, and 1GB is equal to 1024MB, so 2^23 square bytes is 4GB.

So how does the program work?

The developed software is placed on the hard disk of our computer, such as the QQ software we often use on the computer, click the QQ icon —> right click —> properties. You can see that QQ is an .exe executable file. When we double-click QQ, the QQ program will run.

The program must be placed in the slave memory first during the running process. Take this QQ as an example, the QQ.exefile must be a file generated by a certain compiler. By writing the code in the compiler, and then compiling and linking, the functions, codes, variables, etc. we have learned are converted into 010101 numbers that can be executed by the computer CPU. That is, the code we wrote contains a lot of machine code and CPU instructions that the CPU can recognize. The generated .exefile contains 0101010101... instructions. The CPU reads the data in the memory, and reads instructions to control the execution of corresponding operations. There are registers, arithmetic units and controllers inside the CPU. Because the register is inside, the data that needs to be calculated in the memory must first be taken into the register for operation, and the calculated data is sent back to the memory.

Usually, the CPU will first store the data in the memory into the register, and then perform operations on the data in the register. Suppose there is a red memory space in the memory with a value of 3, and now I want to add 1 to its value and store the result in the blue memory space.

1. The CPU first puts the value of the red memory space in the EAX register: mov eax, red memory space
2. Then add the EAX register to 1: add eax, 1
3. Finally, assign the value to the memory space: mov blue Color memory space, eax

Guess you like

Origin blog.csdn.net/qq_39400113/article/details/113334599