Memory is where temporary data is stored. The running programs, the pictures you are viewing, the texts you are editing, and the tutorial you are reading now are all copied to the memory.
Reference address:Chapter 4 Memory Data (X86 Assembly Tutorial)
This chapter is about memory data. Nowadays, computers have over G of memory. But did you know that when the computer was first turned on, a maximum of 1MB of memory could be used! This is because the CPU actually has several modes, real mode, protected mode, and 64-bit mode (I won’t talk about the more powerful modes later, because... I don’t know either!) To access memory, addressing is required. When the computer was first turned on, the CPU was in real mode. What is real mode? That was the 16-bit mode of the CPU a long time ago. At that time, the computer had only 1M memory. B, that is to say, the addressing mode only needs to be able to address 1MB. Naturally, it is impossible to use all the G memory. Later, the 32-bit protected mode of 80386 CPU came out (in fact, there was an 80286 in the middle, and there was a protected mode since 286, but it seems not to be 32-bit), and the register of 386 protected mode is 32 bits. It can address 4GB of memory (for the time being, only the real mode is taught, and the protected mode and the like will not be explained in detail. I will see if it can be written into this tutorial later). Now the newly appeared 80686 has a 64-bit mode, and the register is 64 bits.
Well, let's talk about the addressing method of real mode. Memory is one-dimensional, and data is arranged in a line. To access memory, you need to provide a memory address. The address of the first byte of memory is 0 (in computer mathematics, 0 is the starting point). Yes, that's it. The address of the second byte is 1. And so on. The addressing method is the way to provide an address to access memory. In real mode, registers have 16 bits, which means that a single register can only express an address of up to 64KB (please verify it yourself, the verification method is: use the binary mode of the calculator, enter 16 1s, and convert to decimal)
64KB! That's obviously not enough! Therefore, real mode addressing uses 2 registers for addressing, and addresses in the "segment: offset" manner.
As mentioned above, the segment registers CS, DS, ES, and SS are used for addressing and storing the data of the "segment". As for the data of the "offset" part... it can be represented by any of the registers BX, SI, DI, SP, IP, and BP, or directly by numbers. Example:
CS:BX
CS:1234
So, how does "segment:offset" express a one-dimensional address? See below:
The CPU notifies the memory where it wants to operate through the address line. There are 20 address lines in the CPU, that is, the "segment: offset" addressing method can only address 20-bit addresses (so even if two 16-bit registers are combined, it is not possible to address a 32-bit memory address...), 20 bits, that is, 1MB. So, how to convert two 16-bit data into 20 bits?
The algorithm is as follows:
(segment*16)+offset
Well, the value in the segment register is multiplied by 16 (10 in hexadecimal) and added to the offset address.
Example:
Segment register = 15
Offset address = 128
So the memory address obtained is: (15*16)+128=368
Well, we have finished talking about addressing mode. Next, we will talk about the order of low and high bits of data. In the future, you will encounter some situations where numbers are stored in reverse, for example, 53,217 is stored in memory as 71235. This is because the high and low bits are arranged in order. In this number, 7 is the ones, so it is at the front, 1 is the tens, so it is the second. And so on. Maybe you have been shocked to find that, yes, the numbers in the computer are not reversed, but the numbers we use in reality are reversed. We use 53217 to represent 53,217, and we put the highest 5 in the ten thousandth place at the front! The same is true in the register, the low bit is in the front and the high bit is in the back.
Next, let's talk about the way numbers are represented in assembly. In assembly, you can enter numbers in decimal, binary, hexadecimal, etc. (Of course, after compiling and generating code, they are all in binary.) With so many bases, if there is no explanation, the assembly compiler will definitely make a mistake. So how do we tell the compiler which number is in which base?
We can add an English letter after the number to represent it. For binary numbers, add B after it, for example: 01110011B. For hexadecimal numbers, add H after it, for example: 1F3AH. As for decimal numbers, it is not necessary. All numbers have an English letter after it, so it doesn't matter if one of them doesn't have an English letter, right? Because decimal numbers are the most commonly used, it is given the right not to have an English letter after it. In assembly, decimal numbers do not need to be represented specially.
In addition, since hexadecimal involves English letters, ABCDEF, it may be confused with the assembly code, so if the first digit of the hexadecimal is an English letter, a 0 must be added in front.
Example:
A2H
Must be written as:
0A2H
Okay, that’s all for this chapter~
Previous article:Chapter 6 Hands-on Operation - Use of DEBUG 2 (X86 Assembly Tutorial)
Next article:Chapter 2 Some Data Units (X86 Assembly Tutorial)
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
Guess you like
- I need help designing a 100mA constant current source. I already have a circuit and need analysis.
- FPGA digital electronic system design and development example navigation.pdf
- The Hall sensor signal is asymmetric and the HALL C high level is too low. What is the cause? How to solve it?
- The company's idle equipment, antique goods, if you need them, come
- Pay attention! Nine commonly overlooked ADC technical specifications
- Analysis of transistor drive circuit and level conversion
- Programmable high pass filter
- EEWORLD University Hall----Live Replay: How Microchip protects your IP in cloud service connections
- TI Bluetooth Solutions FAQs Frequently Asked Questions
- Free: Pingtouge RISC-V development board worth 390 yuan (100 sets in total), share the event to win a 100 yuan red envelope