Home >Common Problem >If bp addressing is used when accessing memory, what is the default segment register?

If bp addressing is used when accessing memory, what is the default segment register?

青灯夜游
青灯夜游Original
2020-10-19 11:49:119832browse

If you use bp addressing when accessing memory, the default segment register is "SS", which is the stack segment. The SS stack segment usually refers to a memory area that works in stack mode; in an architecture that uses segmented memory management for program memory allocation, the stack segment is used to store local variables and function return addresses.

If bp addressing is used when accessing memory, what is the default segment register?

#The segment register is set for segmented management of memory. Computers need to segment memory to allocate it to different programs (similar to hard disk paging). When describing memory segmentation, the following segment information is required: 1. Size of the segment; 2. Starting address of the segment; 3. Management attributes of the segment (writing prohibited/execution prohibited/system exclusive, etc.). It is necessary to use 8 bytes (64 bits) to store this information, but the segment register only has 16 bits, so only the segment number (segment selector, also translated as "segment selector") can be stored in the segment register, and then the segment number is mapped to the existence GDT (global (segment) descriptor table, global segment number record table) in memory reads segment information.

8086CPU has 20 address lines, and the maximum addressable memory space is 1MB. The 8086 registers are only 16 bits, and the instruction pointer (IP) and index register (SI, DI) are also 16 bits. It is impossible to address 1MB of space with a 16-bit address. Therefore, the memory must be segmented, that is, the 1MB space is divided into 2^4, that is, 16 segments, each segment does not exceed 64KB (2^16, 16-bit data lines can be addressed). Four 16-bit segment registers are set up in the 8086 to manage four types of segments: CS is the code segment, DS is the data segment, SS is the stack segment, and ES is the additional segment. After the memory is segmented, each segment has a segment base address. The segment register stores the high-order 16 bits of the segment base address. This 16-bit address can be formed by shifting the 16-bit address to the left by four bits (adding 4 zeros after it). 20-bit segment base address.

The segment register CS points to the memory segment where the program is stored. IP is used to store the offset of the next instruction to be executed in the segment. Putting them together can fetch the next time in the memory segment. The instruction to execute.

The segment register SS points to the memory segment used for the stack, and SP is used to point to the top of the stack. Putting them together can access the top unit of the stack. In addition, when the offset uses the pointer register BP, its default segment register is also SS, and BP can be used to access the entire stack, not just the top of the stack.

The segment register DS points to the data segment, and ES points to the additional segment. When accessing the operand, one of the two is combined with an offset to obtain the physical address of the storage unit. The offset can be one of a specific numerical value, a symbolic address, the value of a pointer register, etc. The specific situation will be determined by the addressing mode of the instruction.

Usually, the default data segment register is DS, with one exception: when performing string operations, the segment register of the destination address is specified as ES. Of course, in general instructions, we can also change the segment register of the operand by changing the "segment replacement" field in the prefix.

"Optional segment registers" are segment addresses that can be used to force the values ​​of these segment registers as their operand addresses.

The above is the detailed content of If bp addressing is used when accessing memory, what is the default segment register?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn