c - x86 - C 使用虚拟地址还是线性地址?

标签 c assembly x86 memory-address

假设您处于 x86 保护模式,因此启用了分段。

考虑这段代码:

// main
int stackvar, *ptr;

// ptr may contain the address of a variable located in the stack segment
ptr = &stackvar;

// ptr may contain the address of a variable in the heap (data segment)
ptr = (int *) malloc(sizeof(int));

我读到ptr只包含偏移量(即虚拟地址),不包含段的指示。这意味着它应该与段基地址结合以获得线性地址。是真的吗?

// let %eax = ptr
asm("movl (%eax), %ebx"); // which segment is used by this instruction?

如果 %eax 只包含偏移量,而不包含段的指示,机器如何知道应该应用哪个段基地址(例如数据或堆栈段基地址)?

最佳答案

如果不使用显式段覆盖,则有隐式段附加到许多操作码 - 请参阅汇编程序手册。

关于c - x86 - C 使用虚拟地址还是线性地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23757501/

相关文章:

C:遍历 char 数组,修改文字

c - 为什么这个指向函数的指针可以在没有警告或错误的情况下工作?

c - C 程序的类似 Hibernate 的功能

assembly - 我可以将返回地址保存在寄存器中并将其推回堆栈中 NASM x86_64 中的 `ret` 之前吗

assembly - 字大小的 OUT 到字节 IO 寄存器?使用旧 VGA 代码中的指令设置序列 Controller 寄存器

c++ - 简单的音频处理库?

c - undefined reference `explain_read' ......没有这样的文件或目录

linux - x86 上的任务管理

c++ - 写一个新的 jit

c - 如何从汇编代码调用 C 函数