Intel 64、rsi 和 rdi 寄存器 [英] Intel 64, rsi and rdi registers

查看:127
本文介绍了Intel 64、rsi 和 rdi 寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Intel 64 架构中有 rax..rdx 寄存器,它们只是 A..D 通用寄存器.

in Intel 64 architecture there is the rax..rdx registers which are simply A..D general purpose registers.

但也有称为 rsi 和 rdi 的寄存器,它们是源索引"和目标索引"寄存器.为什么这些寄存器有实际名称(与 A 等相比)?
源索引"和目标索引"实际上是什么意思?是否有一些约定说这些寄存器应该在特定情况下使用?

But there are also registers called rsi and rdi which are the "source index" and "destination index" registers. why do these registers have actual names (compared to just A, etc)?
What does "source index" and "destination index" actually mean? And is there some convention that says these registers should be used in specific circumstances?

推荐答案

这些寄存器最初隐含地用于重复指令中,例如 MOVSB,它从 DS:SI<复制一个字节/code> (DataSegment:SourceIndex) 到 ES:DI(ExtraSegment:DestinationIndex),在实模式下具有分段内存的 16 位计算机时.也可以作为 16 位寻址模式的索引寄存器,如 [bx + si].

These registers were originally implicitly used in repetitive instructions, for instance MOVSB, which copy a byte from DS:SI (DataSegment:SourceIndex) to ES:DI(ExtraSegment:DestinationIndex), at the time of the 16-bits computers with segmented memory in real mode. And also as index registers in 16-bit addressing modes like [bx + si].

现在,这些寄存器例如用于传输 UNIX 的 x86_64 ABI,与它们的原始目的相去甚远.(另见 i386 和 x86-64 上的 UNIX 和 Linux 系统调用的调用约定是什么)

Right now, these registers are for example used to transmit the first two (integer) function parameters in UNIX's x86_64 ABI, far from their original purpose. (See also What are the calling conventions for UNIX & Linux system calls on i386 and x86-64)

rXX 64 位寄存器的名称清楚地表明,旧寄存器名称仅用于熟悉和复古兼容性.(但请注意,某些指令仍然仅适用于某些寄存器,例如 rep movsb 仅用作 memcpy(rdi, rsi, rcx)实际上为什么选择 RDI 和 RSI 作为前两个参数- 在 x86-64 System V ABI 中传递寄存器:一些函数使用它们的前 1 或 2 个参数调用 memsetmemcpy,因此内联 rep在这种情况下,movsb/d 更便宜.)

The names of the new rXX 64-bit registers clearly show that old register names are only here for familiarity and retro-compatibility. (But note that some instructions do still only work with some registers, for example rep movsb only works as a memcpy(rdi, rsi, rcx), and is in fact why RDI and RSI were chosen as the first 2 arg-passing registers in the x86-64 System V ABI: some functions call memset or memcpy with their first 1 or 2 args, so inlining rep movsb/d is cheaper in that case.)

这篇关于Intel 64、rsi 和 rdi 寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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