80x86CPU learning

This blog post is used to document some confusion about hardware understanding and some basics of 80x86 series CPUs.


CPU时钟(clock, clock pulse, clock rate, cycle)

  • Clock: A computer (CPU) uses a clock to synchronize the instructions executed by the CPU. (I don't understand and continue to look down)

  • Clock pulse (clock pulse) and clock frequency/clock frequency speed (clock rate/speed): The clock pulse has a fixed frequency, and this frequency is called the clock frequency. For example, if you buy a 2.60GHz notebook, 2.60GHz is the clock frequency (win10 can be viewed through My Computer -> Properties). Unlike the clock in our daily life, the clock of the CPU runs in minutes and seconds. It runs according to this fixed clock frequency (rate/speed), which is similar to the beat.

  • Clock cycle (cycle): The clock cycle is the reciprocal of the clock frequency. One clock cycle can be understood as the number of beats per unit time of the CPU, and in one clock cycle, the CPU can only complete one basic action. (The number of clock cycles (the number of ticks) depends on the algebra and model of the CPU; the number of cycles of an instruction depends on the instruction before it and other factors [specific factors, currently unknown to the author.])


80x86 series CPU registers and three modes (real mode, 16-bit protected mode, 32-bit protected mode), the following only introduces some basic registers

  • 8088, 8086: Several basic 16-bit registers : AX, BX, CX, DX, SI, DI, BP, SP, CS, DS, SS, ES, IP, FLAGS. The 8088 and 8086 only support 1MB (2 20 ) memory addressing (20-bit external address bus) and real mode . In this mode, a program can access any memory it wants, even the memory of other programs. In 8088 and 8086, the program segment (the program should be loaded into memory in segments) cannot exceed 64K (2 16 ).

  • 80286: Compared with 8088 and 8086, 80286 adds some new instructions. An important point is that the 80286 adds a new mode: 16-bit protected mode . In this mode, programs can access up to 16MB of memory (24-bit address bus) and protect programs from accessing each other's memory. However, the block of 80286 still cannot exceed 64K (2 16 ). This is because the offset is still 16 bits in 16-bit protected mode .

  • 80386 (i386): Brings the PC from the 16-bit era to the 32-bit era. On the basis of 80286, many registers have been added, and 32-bit protected mode has been introduced . In this mode, programs can access up to 4GB of memory (32-bit address bus) and can protect programs from accessing each other's memory. The program segment of 80286 can reach 4GB (2 32 ).


Introduction of three modes

real mode

According to the above, the memory that the program can access in real mode is only 1MB (2 20 bytes), and the effective address range (hexadecimal) is 00000-FFFFF. Obviously, to represent these addresses we need 20 bits of binary, and our 8086/8088 registers are up to 16 bits. To solve this problem, Intel Corporation uses two 16-bit binary numbers to determine the address to be accessed. The first 16-bit binary number is called selector and is stored in the segment register; the second 16-bit binary number is called offset . And the 20-bit physical address is calculated by the 32-bit selector:offset pair by the following formula:

16 * selector + offset

For example, the physical address given by 047C:0048 is calculated as follows (a hexadecimal number multiplied by 16 only needs to add a 0 to its rightmost bit. Then the selector is a multiple of 16, such a number is called a paragraph number) : In addition to the lack of memory protection, this mode has the following disadvantages: 1. Because the offset is a 16-bit limit, the code segment and data (data) loaded each time cannot exceed 64KB.

  1. A byte in memory does not have a unique corresponding selector. For example, the physical address 04808 has the following representations: 047C:0048, 047D:0038, 047E:0028 and 047B:0058. This complicates selector comparisons.

16-bit protected mode

The selector value in real mode is a paragraph number, and in protected mode (including 32 bits), the selector is an index value called the Global Descriptor Table (GDT) . Code segmentation in protected mode no longer has to place code segments (segments) in memory as in real mode, but uses a new technology called virtual memory. The basic idea of ​​virtual memory is to keep only the code and data currently used in memory, and other data and code segments are temporarily placed on disk. Each code segment will be allocated an entry in the GDT (the index value of the entry is the selector), which records all the information the system needs to know about the code: whether it is in memory; if it is already in memory, where; readable).
Disadvantage: offset is still 16 bits.

32-bit protected mode

There are two main differences between the 32-bit protected mode of the 80386 and the 16-bit protected mode of the 80286:

  1. The offset is extended to 32 bits, which means that segments can be up to 4GB.

  2. Segments can be divided into units smaller than 4K called pages. In 32-bit protected mode, virtual memory handles pages instead of segments

reference books

PC Assembly Language, Paul A. Carter, November 11, 2003

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325567630&siteId=291194637