8086 中通用寄存器之间的差异:[bx] 有效,[cx] 无效? [英] Differences between general purpose registers in 8086: [bx] works, [cx] doesn't?

查看:43
本文介绍了8086 中通用寄存器之间的差异:[bx] 有效,[cx] 无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 8086 中这种结构是正确的:

In 8086 this structure is correct:

mov bh,[bx]

但这不正确:

mov bh,[cx]

我不知道为什么.我认为通用寄存器(AX、BX、CX、DX、SP、BP、SI 和 DI)是我们可以用于任何目的的寄存器,BX 用于基地址或 CX 用于计数器的声明只是一个约定,它们根本没有区别.但似乎我错了.你能解释一下原因吗?这些寄存器之间的确切区别是什么?(例如为什么我不能将基地址保存在 cx 寄存器中?)

I don't know why. I think that the general purpose registers (AX, BX, CX, DX, SP, BP, SI and DI) are registers that we can use for any purpose and the statement that BX is for base address or CX is for counter is just a convention and they don't differ at all. But it seems that I'm wrong. Can you explain the reason? And what is the exact difference between these registers? (For example why can't I save the base address in cx register?)

推荐答案

在 8086(以及 x86 中的 16 位寻址)上,只有以下寻址模式可用:

On the 8086 (and 16-bit addressing in x86), only the following addressing modes are available:

[bx]       [bx + foo]
[foo]      [bp + foo]
[si]       [si + foo]
[di]       [di + foo]
[bx + si]  [bx + si + foo]
[bx + di]  [bx + di + foo]
[bp + si]  [bp + si + foo]
[bp + di]  [bp + di + foo]

其中 foo 是一些常量值,例如123 或段内符号的偏移量,例如一个文字 foo 来引用某个地方的 foo: 标签.(有趣的事实:编码 [bp] 的唯一方法实际上是 [bp+0],汇编器会为你做这件事.注意表中的 [foo][bp] 的位置;这反映了 x86 机器代码的特殊情况,即编码意味着没有寄存器的位移.)

where foo is some constant value, e.g. 123 or the offset of a symbol within a segment, e.g. a literal foo to reference a foo: label somewhere. (Fun fact: the only way to encode [bp] is actually as [bp+0], and assemblers will do this for you. Notice in the table [foo] is where [bp] would otherwise be; this reflects how x86 machine code special-cases that encoding to mean displacement with no registers.)

bp 作为base 表示SS(堆栈)段;其他寻址模式意味着 DS(数据)段.如有必要,这可以用前缀覆盖.

bp as the base implies the SS (stack) segment; other addressing modes imply the DS (data) segment. This can be overridden with a prefix if necessary.

注意不存在涉及cx的寻址模式,所以[cx]不是有效的内存操作数.

Note that no addressing mode involving cx exists, so [cx] is not a valid memory operand.

寄存器 ax、cx、dx、bx、sp、bp、si 和 di 被称为通用寄存器,因为它们在所有通用指令中都可以作为操作数访问.这与 es、cs、ss、ds(段寄存器)、ip(指令指针)或标志寄存器等专用寄存器形成对比,这些寄存器只能通过为此目的而制定的特殊指令访问.

The registers ax, cx, dx, bx, sp, bp, si, and di are called general purpose registers because they are accessible as operands in all general-purpose instructions. This is in contrast to special-purpose registers like es, cs, ss, ds (segment registers), ip (the instruction pointer) or the flags register which are only accessible with special instructions made just for this purpose.

如您所见,并非所有通用寄存器都可以用作内存操作数的索引寄存器.注册代码时必须牢记这一点.

As you see, not all general purpose registers can be used as index registers for memory operands. This has to be kept in mind when registrating your code.

除此限制外,还有一些指令隐式操作固定寄存器.例如,loop 指令专门对 cx 进行操作,16 位 imul r/m16 指令专门对 dx:ax<进行操作/代码>.如果您想有效地使用这些指令,记住每个通用寄存器的建议用途是很有用的.

In addition to this restriction, there are some instructions that implicitly operate on fixed registers. For example, the loop instruction exclusively operates on cx and a 16-bit imul r/m16 operates exclusively on dx:ax. If you want to make effective use of these instructions, it is useful to keep each general purpose register's suggested purpose in mind.

值得注意的是,lods/stos/scas/movs/cmps 隐式使用 DS:SI 或/和 ES:DI,并且在 cx 上与 一起使用时reprepz/repnz 前缀,因此那些用于在数组上循环指针的寄存器允许代码大小优化.

Notably, lods / stos / scas / movs / cmps use DS:SI or/and ES:DI implicitly, and on cx when used with a rep or repz / repnz prefix, so those registers for looping a pointer over an array allow code-size optimizations.

这篇关于8086 中通用寄存器之间的差异:[bx] 有效,[cx] 无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆