: 运算符在汇编中起什么作用?
: 运算符在汇编中起什么作用? 在如下代码中看到:DS:DX
我还没有找到该操作员的任何文档。 (我正在使用 NASM)
what does the : operator do in assembly?
seen in code like: DS:DX
i haven't found any documentation for this operator.
(im using NASM)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上只是一个寄存器分隔符,而不是一个运算符。这意味着使用
DX
寄存器作为DS
段寄存器基址的偏移量。它实际上为您提供的地址取决于您运行的模式(真实模式或受保护模式)。
例如,在实模式下,段寄存器乘以 16 并添加到偏移寄存器中,得到 20 位物理地址。如果
DS
为0x1234
且DX
为0x5678
:在保护模式下,
DS
为实际上是一个段选择器,用于在表中查找内存的基地址,然后将其添加到偏移寄存器以给出一个值。该值始终是虚拟地址,在确保相关虚拟内存从外部存储调入后,由内存管理单元 (MMU) 映射到物理地址。
That's actually just a register separator, not an operator. It means use the
DX
register as an offset from theDS
segment register base.What it actually gives you as an address depends on what mode you're running in (real or protected).
For example in real mode, the segment register is multiplied by sixteen and added to the offset register to give you a 20-bit physical address. If
DS
is0x1234
andDX
is0x5678
:In protected mode,
DS
is acutally a segment selector which is used to lookup a base address for the memory in a table, then add that to the offset register to give a value.That value is invariably a virtual address which is mapped to a physical address by the memory management unit (MMU), after ensuring that the relevant virtual memory is paged in from external storage.
:
运算符将段寄存器/选择器与通用寄存器区分开来,并表示要访问哪个段中的寄存器值。例如,意味着在 16 位实模式下访问 16 位寄存器。
DX
寄存器中的位值相对于DS
段值的偏移量,以 16 字节值递增(即,段值 0x0000 和 0x0001 之间的差异表示16 字节偏移)。例如,如果DS
中的值为 0xA000,而DX
中的值为 0xFF,那么您将在 0xA00FF 处寻址该值。在 32 位保护模式下,段选择器表示 16 位描述符值,其中第 3-15 位用作 CPU 全局描述符表或本地描述符表中的查找偏移量,其中包含有关 32 位段的信息地址范围,以及该段的环级访问权限(即内核级、用户级等)。位 0-1 表示请求权限级别,可防止用户级进程加载更高权限的段值。位 2 是一个标志,清除时表示在 GDT 中查找该段,设置时表示偏移到 LDT 中。例如,
DS
值为 0x0010 意味着在 GDT 中查找请求权限级别为 0 的第三个槽(即,您需要处于内核级模式才能设置此值) 。然后,DX
中的值将从 GDT 中为该特定段设置的地址范围的起始位置开始偏移。The
:
operator differentiates a segment register/selector from a general-purpose register, and signifies which segment to access the register value in. So for instance,means in 16-bit real mode to access the 16-bit value in the
DX
register offset from theDS
segment value, which increments in 16-byte values (i.e., the difference between segment values 0x0000 and 0x0001 represent a 16-byte offset). So for instance, if the value inDS
was 0xA000, and the value inDX
was 0xFF, then you would be addressing the value at 0xA00FF.In a 32-bit protected mode, the segment selector represents a 16-bit descriptor value where bits 3-15 are used as a look-up offset in the CPU's global descriptor table or local descriptor table which contains information on the 32-bit segment addresses range, as well as the ring-level access permissions for that segment (i.e., kernel-level, user-level, etc.). Bits 0-1 represent the request privledge level, which prevents a user-level process from loading a higher-permission segement value. Bit 2 is a flag, which when cleared means to look up the segment in the GDT, or if set means to offset into the LDT. For instance, a
DS
value of 0x0010 would mean to look up the third slot in the GDT with a request privledge level of 0 (i.e., you would need to be in kernel level mode to set this value). The value inDX
would then be offset from the start of the address range set for that specific segment in the GDT.