assembly - 在没有分页的32位模式下,如何计算物理地址?

标签 assembly x86 memory-address memory-segmentation

我是 assembly 新手,并被赋予以下任务:

If the processor is in protected 32-bit mode without paging, and for the segment connected to the DS selector states in the descriptor table that it starts from 00036D95h, and the EBX register has the value 000034A7h, from which physical locations will the value be moved to AL after instruction MOV AL, [EBX + 0016h]?

我尝试在网络上查找任何类似的示例,但找不到任何内容?有谁知道一些类似的例子,或者任何计算物理位置的公式?

编辑: 你能把这三个数字相加得到物理地址吗?

最佳答案

Could you just sum up these three numbers to get the physical address?

是的,这就是它的工作原理。

Does anyone know some similar examples, or any formula to calculate the physical location?

一般来说,如@Peter@tkausl上面建议,公式是SEGMENT_BASE + OFFSETSEGMENT_BASE 仅由段描述符给出,而 OFFSET 取决于实际指令。对于 MOV 指令(请参阅 Referencing the contents of a memory location. (x86 addressing modes) ),您可以:

MOV REG, [base_reg + index_reg*scale + displacement]

因此完整的公式变为SEGMENT_BASE + base_reg + index_reg*scale + 位移。在您的具体情况下,您只有 base_regdisplacement


供引用,来自Intel® 64 and IA-32 Architectures Software Developer's Manuals第 3A 卷第 3.1 节您可以阅读:

Each segment has a segment descriptor, which specifies the size of the segment, the access rights and privilege level for the segment, the segment type, and the location of the first byte of the segment in the linear address space (called the base address of the segment). The offset part of the logical address is added to the base address for the segment to locate a byte within the segment. The base address plus the offset thus forms a linear address in the processor’s linear address space.

If paging is not used, the linear address space of the processor is mapped directly into the physical address space of the processor. The physical address space is defined as the range of addresses that the processor can generate on its address bus.

下图应该让您了解分页和分段如何协同工作:

fig-3-1

现在由于您没有分页,如果您删除右侧的“分页”部分,则剩下的就是“分段”部分,并且您处于以下情况(注意”或物理内存”在右侧):

fig-3-4

请注意,上图只是示意性的,您不一定需要让每个段寄存器指向不同的段描述符,但可以。

关于assembly - 在没有分页的32位模式下,如何计算物理地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70175306/

相关文章:

c++ - c++指针数组和内存地址分配

ubuntu - x86 程序集 jl 不起作用

C++ 根据成员数量生成的未优化程序集的差异

assembly - 是否可以在程序集中进行自定义中断?

指数幂程序的汇编错误结果

c - c中指向指针的指针,得到意想不到的值

assembly - MMX 和 XMM 寄存器之间的区别?

使用 AND、OR、SHR 和 SHL 指令以及数组将循环从 x86 汇编语言转换为 C 语言

c - 如何在Bochs中的DLX linux中编译C程序

c++ - C: 在 C 中编译 C++ 代码