假设您处于 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/