STOSB 使用额外段有什么特殊原因吗? [英] Is there any special reason for STOSB to use extra segment?
问题描述
我读过 STOSB
的功能如下:
I have read that STOSB
functions like this:
ES:[DI] <-- AL
如果 DF = 0
递增 DI
否则递减 DI
.
If DF = 0
increment DI
else decrement DI
.
- 那么为什么
STOSB
不会改变DS:[DI]
? - 使用额外段有什么特殊目的吗?
- 在大多数字符串指令中,我们使用额外的段.为什么?
推荐答案
那么为什么 STOSB 不改变 DS:[DI]
So why STOSB doesn't change DS:[DI]
因为这个定义会与已经使用 DS:[SI]
的 LODSB
的使用发生冲突.使用单独的段寄存器可为您提供更大的灵活性.
Because this definition would collide with the use of LODSB
which already uses DS:[SI]
. Using a separate segment register gives you more flexibility.
使用额外段有什么特殊目的吗?
Is there a special purpose for using extra segment?
是的.您可以在处理段时轻松地在段之间传输字节.例如,您可以使用 LODSB
从 DS:[SI]
加载 AL
,修改 AL
然后存储它使用 ES:[DI]
到一个不同的段,Extra Segment,STOSB
.在具有 16 位段大小和 20 位地址空间的 8086 中,这非常有用.
Yes. You can transfer bytes between segments easily while processing them. For example, you can use a LODSB
loading AL
from DS:[SI]
, modify AL
and then store it to a different segment, the Extra Segment, with STOSB
using ES:[DI]
. In 8086 with its 16-bit segment size and a 20-bit address space this is really useful.
另一个说明用法的指令是REP MOVSB
指令,它从DS:[SI]<复制一个字节序列(长度在
CX
中)/code> 到 ES:[DI]
.
Another instruction illustrating the use is the REP MOVSB
instruction which copies a sequence of bytes (with its length in CX
) from DS:[SI]
to ES:[DI]
.
(如果您在复制时不需要检查每个字节,您只需使用 rep movsb
或 rep movsw
以获得比 更好的性能lods
/stos
循环.)
(If you don't need to examine each byte as you copy it, you'd simply use rep movsb
or rep movsw
for better performance than lods
/stos
in a loop.)
在大多数字符串指令中,我们使用额外的段.为什么?
In most string instructions we use extra segment. why?
嗯,不是大多数,但可能大约有一半.使用另一个段寄存器为您提供了快速访问不同段的优势——您不仅限于处理一个 64KB 段中的数据,而且不必在每次访问不同段之前更改 DS
寄存器.
Well, not in most, but maybe roughly in half of them. Using another segment register gives you the advantage of quick access to different segments - you are not limited to processing data only in one 64KB segment and do not have to change the DS
register before each access to a different segment.
stos
和 movs
写 es:[di]
,这是有道理的,因为 DI
是目标索引"寄存器.
stos
and movs
write es:[di]
, which makes sense because DI
is the "destination index" register.
cmps
和 scas
从 es:[di]
读取,这对于 scas
来说可能令人惊讶,因为它只有一个内存操作数,因此您可能希望它像 lods
一样从 ds:[si]
读取.特别是因为 SCASB 设置了来自 AL - [mem] 的标志
,而不是相反,所以它就像一个 cmp
,其中内存是右操作数(源),而不是左(目标).像 cmp al, es:[di]
.
cmps
and scas
read from es:[di]
, which is maybe surprising for scas
because it only has one memory operand so you might expect it to read from ds:[si]
like lods
. Especially because SCASB sets flags from AL - [mem]
, not the other way around, so it's like a cmp
where memory is the right operand (source), not left (destination). Like cmp al, es:[di]
.
也许 8086 指令集的架构师想象了一个循环的用例,它执行 lods
和 scas
以在段之间实现 strcmp
.
Perhaps the architect of the 8086's instruction set imagined a use-case of a loop that does lods
and scas
to implement strcmp
between segments.
这篇关于STOSB 使用额外段有什么特殊原因吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!