In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis of the underlying computer technology in assembly language. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. Machine language
What is language is a tool for communication between people. And the assembly language is the language of the computer.
Machine language (binary):
Mainstream electronic computers use binary, and computers only know 0 and 1, because there are only two states in the circuit, either powered on or off. We use numbers to indicate that these two states are 0 and 1. We can use 0 and 1 to communicate with the computer.
Machine language is a language made up of 0 and 1, which is difficult for us to understand, almost impossible to understand. When we need to simplify these complex machine languages (a bunch of 0 and 1 numbers), we need aids (INC DEC MUL DIV, etc.), that is, assembly language.
Once we have mastered the assembly language, we can operate the bottom of the computer, and if we go deeper, we can directly manipulate the bits in the computer.
Assembly language helps to memorize machine language, so when we learn assembly language, we learn machine language.
Learning assembly is to understand how the computer operates and how each line of code is executed by the computer. These principles are very important!
two。 The essence of binary thought
Obstacles to learning the base system:
The main reason why many people do not understand the system is that we have accepted the concept of decimal system since childhood, and the principle of "ten into one" is deeply rooted in the hearts of the people.
Man's instinctive choice is the decimal system.
Common base system:
Base 1: every one into one, 1 1
Binary system: every binary into one, computer base
Octal: every octal, composed of 8 symbols: 0 1 2 3 4 5 6 7
Base 10: every decimal one, composed of 10 symbols: 0 1 2 3 4 5 6 7 8 9
Hexadecimal: every hexadecimal, composed of 16 symbols: 0 1 2 3 4 5 6 7 8 9 a b c d e f
The base is actually very simple, only need to be able to check the number.
Test:
The base can be customized:
Xiao Zhu's decimal system: 0 24 7 8 a b r d f, can be defined as you like.
This allows me to use binary encryption to prevent it from being blown up (brute force cracking).
3. Binary system
Current computers (electronic computers) use binary 0 1
Today's computers (electronic computers):
The circuit is realized through the integrated circuit with and without electricity, high level and low level, showing two values of 0 1.
Because binary is very troublesome to write, we need to abbreviate binary, so we write hexadecimal.
Expand:
The Quantum computer of the Future: (preaching)
A machine that can perform quantum computing.
The unit of a quantum computer: qubits. That is, the so-called (qubits), the two states of the quantum (photons, magnetic fields).
The quantum computing speed is much faster than the current electronic computing speed.
Photon: orthogonal polarization direction.
Magnetic field: the spin direction of an electron.
Now that we have come to the 21st century, the computing power is coming to an end, and there is no way to break through the essential problem.
If we want to break through this essential problem, we have to use quantum computers. The core element is to improve the computing power of the computer!
In 2019, Google researchers unveiled their latest 54-bit quantum computer, which can calculate what the world's largest supercomputer takes 10, 000 years to perform in just 200 seconds.
On June 18, 2020, Honeywell launched a quantum computer with a quantum volume of 64!
Honeywell also said it would get at least 10 effective qubits, equivalent to 1024 qubits, within a year.
If it can be mass-produced and popularized to civilian use on a large scale, we programmers are the first to use them. Because we're gonna
Write programs for quantum computers.
Why do we learn to understand binary?
If we understand the concepts of registers, memory, and bits, every bit at the bottom of the computer has meaning (the basis of an introduction to assembly). Each 0 and 1 represents a state in which the computer performs specific functions. When the program is running, it will change quickly, and each change will produce a different state, such as: why does the mobile mouse move? how to realize this bottom layer is very complex.
4. Data width
The memory of the computer is limited, and the memory cannot be infinite. So we need to increase the width of the data.
In the field of computing, we have to remember: all memory, all operations, have to add width to the data, especially the strong-typed language such as Cforce Category Java, which needs to define data types! Why do you need to define types? Because the underlying computer needs us to define the width of this data.
With the width, there are some basic quantities. Common usage includes bytes, words, double words, etc.
Bit (bit): 0 1
Byte (byte): (8 bits) 0-0xFF
Word (word): 0-0xFFFF
Double word (dword): 0-0xFFFFFFF
In a computer, every piece of data needs to be typed. The reason for defining a type is to define its width. The width in memory.
5. Signed and unsigned numbers
The computer doesn't know whether the number we write is positive or negative. We can judge by the plus or minus sign, but how does the computer express the plus or minus? Let's find out next!
The data are all wide. So what does each data represent?
Rules
It's like analyzing an audio: for example, why can NetEase Cloud release MP3? That is because there is a MP3 encoding format, according to which we can decode the corresponding format of the sound. If it is a video, you have to abide by the video decoding rules.
Now we need to add a rule to binary decoding.
1. Unsigned number rule:
What your number is, that's what it is, it doesn't matter whether it's positive or negative.
1 00 1 1 0 10 convert hexadecimal to: 0x9A decimal: 154
two。 Signed number rule:
The highest bit is the symbol bit. If the highest bit is 1, it represents a negative number. If the highest bit is 0, it means it is a positive number.
1 00 1 1 0 10 how to convert hexadecimal?
Here is a set of computer rules: that is, the original code anti-code complement.
6. Original code anti-code complement
Why learn the original code and anti-code complement?
Because we're going to use it to calculate later.
Coding rules: (there is nothing to say about the coding rules of unsigned numbers, just what numbers are written.)
Signed number coding rules have three states: * * original code, inverse code, and complement code. * * Let's learn about these three states accordingly.
1. Source code: the highest bit is the symbol bit, align its bit to carry on its own absolute value.
two。 Inverse code: divided into positive and negative numbers
Positive number: the inverse code is the same as the original code. Negative number: the symbol bit must be 1, and the other bits are inverted to the original code.
3. Complement:
Positive number: the complement code and the original code are the same negative number: the symbol must be 1, and the inverse code is + 1.
For example:
Now I'm talking about eight digits. If it's a positive number, it's all the same. Take value to 1: original code: 00000001 inverse code: 00000001 complement: 00000001 if it is negative to-1 value: original code: 100000001 inverse code: 1111110 complement: 11111111 pair-7 value: original code: 1000011111 inverse code: 11110000 complement: 1111100complement 1 to 3: 5 values: the binary of 3 is 115,101 adds up to 1000.
Now we have to understand a sentence, if you see a binary number. You need to know whether it is a signed or unsigned number.
Expand:
Next, let's expand a register: you can store values in it. There are eight general-purpose registers that can store arbitrary values. I can store a value in a register through the mov instruction, as shown in the following figure:
Now I'm going to write a-1, and let's see what the difference is:
The FFFF FFFF here is the value of-1 that we stored in the register. An F is 1111, and the first highest value is 1, so it means he is a negative number. When we normally save 1, the first place is obviously 0, and save-1 becomes FFFF FFFF. Because-1 is stored as a complement in the computer, negative numbers are stored as a complement in our computer. So it is most effective to learn to view through direct operation.
FFFF FFFF stands for thirty-two ones, and if it's unsigned, it means it's positive. If it is signed, it means that it is a negative number, which is very different in nature.
After we understand the original code anti-code complement, we later know how the bottom layer of the computer stores numbers: positive numbers are stored normally, because no matter the original code and anti-code complement, positive numbers are the same. And the negative number is mainly the complement! If you know this, it is for the following bit operations to deal with.
7. Bit operation
As we said before, computers can now store all numbers (positive, floating point, characters), both positive and negative. If we can calculate these numbers, we can do everything in the world. No matter how complex the operation is, the bottom layer is addition, subtraction, multiplication and division. We just need to remember and break through how the bits of the bit operation operate.
Next, let's learn bit operations.
First of all, there is a high-frequency interview question: 2: 8 the most efficient calculation method?
This problem is very slow no matter how, only through bit operation is the fastest, such as moving to the left and right. And remember: many low-level debuggers (such as C debuggers) need bits to determine the state of the CPU when we handwrite the debugger.
Bit operation is what we often call and or non-XOR operation and so on. Let's look at it one by one:
And operation:
It is represented by the & symbol in Java, but it is represented by and and in assembly. The following pictures are easy for us to understand:
1011 00011101 1000-with the result of the operation 1001 0000
Or operation:
It is represented by (|) in Java and or in assembly language, and there is also a circuit diagram that can help to understand:
1011 00011101 1001-or arithmetic 1111 1000
XOR operation:
It is represented by (^) in our Java language and xor in assembly language. To put it bluntly, remember one sentence: the difference is 1. Let's take another circuit diagram to understand:
1011 00011101 1000-XOR 0110 1001
Non-operation (unary operator):
What we call negative (non) in Java is (! ), which is (~) in C language and not in assembly language.
To put it bluntly: 0 is 1, 1 is 0.
1101 1000-non-arithmetic 0010 0111
Through these, we can complete our addition, subtraction, multiplication and division. How to add, subtract, multiply and divide through bit operation?
Bit operation:
It is a moving bit, which is divided into left shift and right shift. (move left * 2, right / 2).
Move left (shl):
0000 0001 all binaries are shifted to the right by a number of bits, and the low bits are discarded, and the high bits are filled with 0 or 1 (according to the symbol bits, negative numbers add 1, positive numbers fill 0) 0000 0000 if you want to take the value (C++) int a = 10 × printf ("% d\ n", a > > 2)
Summary: the essence of assembly is to operate binaries.
Addition, subtraction, multiplication and division are realized by binary and bit operations.
8. Addition, subtraction, multiplication and division of bit operations
Next, we will talk about how to add, subtract, multiply and divide through bit operations. Our computer only knows 0 and 1, but the basic mathematics is based on addition, subtraction, multiplication and division. (addition is done, everything is done)
Let me give you an example: ask for 4: 5?
How does the computer operate? 0000 01000000 0101-(addition, the computer will not add directly) 0000 1001 so what is the implementation principle of the computer? How do you add up the two numbers? The core is: XOR. The first step, XOR (not the same as 1): if you do not consider carry, XOR can directly produce the result 0000 01000000 0101-0000 0001 the second step, the computer is doing and operation on this XOR result: and operation (judging carry), if and operation result is 0, then there is no carry. Step 3, 0000 01000000 0101-0000 0100, move the result of the operation to the left. 0000 0100-> 0000 1000 (the result of carry) the fourth step is still an XOR operation. (the result of the first step XOR and the third step and the carry result of the operation are once again XOR) 0000 00010000 1000Murray 1001 step 5, do an and operation to determine whether it has a carry or not. (as in the second step) 0000 00010000 1000murafure 0000 the last step and the result of the operation is 0000 0000, the circuit is broken and the light bulb is completely off, so the final result is: the result of the last XOR operation with the result of operation 0: 0000 1001 (binary 9) if the and operation is not 0, continue the cycle.
For example: ask for 4-5?
As we said, there is no so-called subtraction in computers, so how does computers operate? 4-5 to put it bluntly, 4 + (- 5) 0000 01001111 1011 (for binary-5)-(subtraction, the computer will not directly subtract) 1111 1111 (8 1s is ff, so ff represents-1) 0000 01001111 1011 Muffin-XOR (if carry is not considered XOR can directly give the result) 1111 11110000 01001111 1011 (judging carry), if the result of the sum operation is 0, then there is no carry. 0000 0000 final result 1111 1111 (hexadecimal ff, decimal-1)
For example:
Multiplication: X * y, which is essentially the addition of y x, or addition.
Division: X / y, the essence is subtraction, which is how many y can be subtracted by x.
Conclusion:
Computers can only add!
9. Assembly language environment description
So far, we can design our own set of binary rules from scratch. We design the circuit to add, subtract, multiply and divide. But the final result of multiplication and division is a binary. For example, if we have 32 bulbs, we can display 32 values, and the number of bulbs on is the final result. Manually convert this result and value! (decimal to binary conversion)
Machine language does not do many things, it is "stupid". To put it bluntly, machine language is bit operation, (addition, subtraction, multiplication and division)
It's all realized by circuits. This is the lowest nature of the computer.
However, we found that after learning these things, we still do not understand, but only to improve the understanding of the current program. But if we want to understand and write the program, can't we really write it?
Through the machine language to achieve the addition calculator, this is the design circuit.
We replace some of our binary coding with instructions! For example: the addition operation just now is through various operations, can it be calculated by a symbol? For example, I want to call it (ADD instruction). Suppose I send an ADD instruction to the computer, which converts my instruction into machine language (that is, compiled) ADD instruction into binary operation.
To put it bluntly, the bottom layer is still binary, but binary is too troublesome to write. At this time, we send some operations to the computer by assembling instructions, and then let the computer execute. This place is going to involve the compiler! Because the compilation command we are talking about is not directly recognizable by the machine, we need to transcode the command into information recognized by the computer, otherwise it cannot be recognized. At this time, it involves the development of compilers.
If you learn from the bottom, be sure not to use particularly intelligent compilers (IDEA,VSCODE, etc.), that is, the more ancient the better (notepad, vim, etc.). Many people learn to use C language, using vim editor to write C language and gcc to execute it. This is the right way to learn C. The bosses at the bottom are almost all the most primitive idea.
Before learning to assemble, you need to master the configuration of the environment:
Vc6 (understanding from program to assembly, realized by C language)
OD
Bag grab tool
Encryption and decryption tool
Try not to use java to learn assembly, after learning assembly to learn jvm will feel very easy. But if I learn java and then learn assembly will be a bit painful, I suggest using C++ to learn assembly. Because C++ can see the address of the memory directly, you can print the address of the memory directly through the pointer and judge the information by the address.
The purpose of learning assembly is not to write code, but to understand the nature of the program.
If you understand assembly, you will be able to understand all complex concepts.
If we are an application programmer, others can not debug the program, if we have learned assembly, we can debug. Because you know exactly what the underlying stack does. If you are doing security (anti-plug-in, anti-virus), you should understand all the knowledge compiled into binary.
Today's computers are at least 32-bit, and some are 64-bit. We need to know that it evolved from 32 bits. The underlying architecture has not changed, but there are more registers, mainly due to the increase in addressing capacity.
Introduction to assembly: understand the corresponding relationship between the assembly and the program, and the nature of the program.
Learned these, do not understand the java source code to understand. Compilation is very important! This is of great help to us in our upward study. Some programming techniques can not be learned, a large reason is that the bottom is not enough. If you are proficient at the bottom, you will find it too easy to learn a programming language.
10. Understanding of registers
To learn compilation, you need to learn three important concepts:
Register
Memory
Assembler instruction
General register: can store any value
Store data: CPU > memory > hard disk
CPU is divided into 32 bits and 64 bits.
32 bits: 8 16 3264 bits: 8 16 3264
There are only 8 32-bit general-purpose registers:
The range of stored values in the register: 0 ~ FFFFFFFF
How does the computer store values in registers?
For binary, it is to modify the value directly. However, to modify the value, you need to find the corresponding location, so there is a memory address.
Mov instruction
Mov storage address, number of deposits
Mov memory address 1, memory address 1
You can write numbers to the register, and you can write the values in the register to the register.
The essence of computer: computing power! Just to calculate! (the mouse cursor is calculated when the mouse cursor is moving)
Different registers:
32 bits represent eight F (FFFF FFFF) An F represents 4-bit (1111) FFFF FF 32-bit 16-bit 8-bit EAX AX ALECX CX CLEDX DX DLEBX BX BLESP SP AHEBP BP CHESI SI DHEDI DI BH
For 8 bits: l for low 8 bits and H for high 8 bits
The top eight bits of FFFF occupy the first two FF, and the low eight bits occupy the last two FF.
In addition to these general registers, each of the other registers has its own specific function (for example, power on and off).
We usually write values to general registers.
11. Memory
The registers are small and insufficient. So we put the data in memory.
There is a saying: every application process has the memory space of 4GB. The memory used by the program is a blank check. Although the process of each application has 4GB memory space, it is not that large when it is actually used on the machine.
Physical memory is used only when the program is actually running.
1B = 8bit
1KB = 1024B
1MB = 1024KB
1GB = 1024MB
Suppose it is a 4GB memory computer, which is equal to 4096m = > and finally calculated as bits, which is the maximum capacity that can be stored.
There are a lot of memory addresses and a lot of space in the computer.
Memory address:
Save a number: occupancy size, data width. Where should I deposit it?
There are a lot of memory addresses and a lot of space in the computer. We need to name the space and assign an address and name to each space.
These numbers for memory are our memory addresses. 32 bits (8 hexadecimal values)
32-bit: determine the addressing ability!
FFFFFFFF + 1 = 100000000, the maximum value.
How does bit limit the size of memory?
100000000 memory address * 8 bits: 800000000.
Converted to 4294967296 bytes in decimal / 8Rom.
According to rule / 1024, it turns out to be 4GB (not to be exceeded).
64 bits, more than enough.
So each memory address has a number: you can store values in it by numbering.
Many people don't understand pointers when learning C because they don't understand memory.
How to store the value of memory? (mov instruction)
The stored value needs to know the data width (byte word dword) and address location (custom: 0xFFFFFFFF)
Not any address can be written, only the memory address that the program has applied for can be used.
Assembler how to write values to memory: mov data width memory address, 1mov byte ptr ds: [0x19ff70], 1 the size of the value passed must be equal to the data width, if it can not be put in.
Memory addresses can be written in many ways:
Ds: [0x19FF70+4] (memory address offset): add offset (4), and the address becomes: 0x19FF74ds: [eax] (register): put the value in the register into memory. Ds: [eax + 4] (register offset)
Take an array as an example:
Ds: [reg + reg * {1pm 2je 4je 8}]
Ds: [reg + reg * {1pm 2je 4pm 8} + 4] offset
This is the end of the article on "sample analysis of the underlying technical principles of computers in assembly language". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.