x86 寄存器名称、寻址模式、位移和存储

发布于 2024-12-02 17:35:05 字数 452 浏览 1 评论 0原文

我有一些关于汇编的问题,我正在学习这些问题,但我很困惑。

  1. bx 和 bp 以及 ss 和 sp 之间有什么区别?书上说bx是基址寄存器,bp是基址指针。这是否意味着它们是同一件事?

  2. mov ax, bxmov ax, [bx]mov ax, bpmov 有什么区别斧头,[bp]

  3. 索引寻址模式下disp是什么意思?例如mov al, disp[bx]?或mov al, disp[si]?本书没有解释disp的含义。

  4. 寄存器是在CPU而不是RAM中吗?

    请原谅我的英语,这不是我的母语。

I have a few questions about assembly which I am learning and I am confused by.

  1. What is the difference between bx and bp and ss and sp? The book says that bx is base register and bp is base pointer. Does this mean they are the same thing?

  2. What is the difference with mov ax, bx, mov ax, [bx], mov ax, bp and mov ax, [bp]?

  3. What does disp mean in indexed addressing mode? For example mov al, disp[bx]? or mov al, disp[si]? The book does not explain meaning of disp.

  4. Register is in CPU not RAM right?

    Please excuse my English, it is not my first langugage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无需解释 2024-12-09 17:35:05

天哪,这些 16 位寄存器在 1984 年几乎已经过时了。抱歉,你有一本旧书。尽管如此,现代处理器仍然使用这些东西,所以你的问题是有道理的。事实上,我当时写过一些 16 位汇编,奇怪的是我还记得它。哎呀。

  1. BX、BP、SS 和 SP 只是四个独立的寄存器。 BX、BP 和 SP 是通用寄存器(其他 16 位 GPR 是 AX、CX、DX、SI 和 DI),SS 是段寄存器,您不会经常使用它(当您参考 BP 和 SP)。对每个寄存器的完整答案将比通常的 SO 答案占用更多的空间。但回答你的具体问题 BX 和 BP 是两个不同的寄存器,而不是同一个。 BP 通常用于索引堆栈帧,BX 通常用于索引结构或数组。

  2. MOV AX, BX 将 BX 的内容移入 AX,而 MOV AX, [BX] 将值位于 DS:BX 的内存位置的内容移入进入 AX。也就是说,如果 BX 包含值 500,则第一条指令将 500 移动到 AX 中,而第二条指令将地址 500 的内容(技术上超过段 DS 开头的 500 个字节)移动到 AX 中。 (请注意,像这样的 MOV 指令在不同的汇编器(例如 MASM 和 NASM)中的解释方式存在一些细微的差异。)

  3. DISP 只是“位移”的缩写,是添加到寄存器中的值的数字计算诸如堆栈帧中变量的地址或结构中元素的地址之类的内容。在像 MOV AX, [BX+25] 这样的指令中,25 是位移。

  4. 是的,寄存器是CPU的一部分。

Oh my, these 16-bit registers became all but obsolete in 1984. Sorry you have an old book. Nevertheless modern processors still use these things, so your question makes sense. I actually wrote some 16-bit assembly back in the day and oddly enough I remember it. Yikes.

  1. BX, BP, SS, and SP are just four separate registers. BX, BP, and SP are general purpose registers (the other 16-bit GPRs are AX, CX, DX, SI, and DI) and SS is a segment register, which you don't use too often (it is implicitly used when you reference BP and SP). A full answer to what each of these registers are far would take up far more space than a usual SO answer should. But to answer your specific question BX and BP are two different registers, not the same one. BP is normally used to index stack frames, and BX is normally used to index into structures or arrays.

  2. MOV AX, BX moves the contents of BX into AX, while MOV AX, [BX] moves the contents of the memory location whose value is in DS:BX into AX. That is, if BX contained the value 500, then the first instruction moves 500 into AX, while the second moves the contents of address 500 (technically 500 bytes past the beginning of segment DS) into AX. (Note there are some subtle differences in the way MOV instructions like this are interpreted in different assemblers, such as MASM and NASM.)

  3. DISP is just an abbreviation for "displacement", a number added to the value in a register to compute something like the address of a variable in a stack frame or an element in a structure. In instructions like MOV AX, [BX+25] then 25 is the displacement.

  4. Yes, registers are part of a CPU.

久光 2024-12-09 17:35:05

4:在 x86 架构中,寄存器确实位于 CPU 中,而不是位于 RAM 中。好吧,我不知道任何 1970 年后的体系结构中寄存器没有出现在 CPU 中,但我确实知道寄存器与 RAM 位于同一地址空间的体系结构(例如 8051) - 或者至少是寄存器是一个子地址空间:访问 RAM 的指令可以使用完全相同的指令代码轻松访问寄存器,并且访问是从片外访问 RAM 还是保留在片内寄存器,仅取决于地址用过的。但在 x86 中,寄存器的实时值根本无法通过内存引用指令访问。 (除非您首先显式或隐式地将它们保存到内存中,但我们在这里不讨论这一点。)

4: In the x86 architecture, registers are indeed in the CPU and not in RAM. Okay, I don't know of any post-1970 architectures where registers are not manifested in the CPU, but I do know of architectures (8051, for example) where registers are in the same address space as RAM is - or at least the registers are a sub-address space: instructions that access RAM can just as easily access registers, using exactly the same instruction codes, and whether the access goes off-chip to RAM or stays on-chip to the registers, depends only on the address used. In x86 though, the registers' live values are not accessible at all with memory-referencing instructions. (Unless you explicitly or implicitly save them to memory first, but we aren't talking about that here.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文