简体   繁体   English

IA32-x86 使用专用寄存器作为通用寄存器

[英]IA32-x86 Use special purpose registers as general purpose registers

I'm initiating me in programming in assembler, I'm making some algorithms and the amount of general purpose registers is not enough for that我开始在汇编程序中编程,我正在制作一些算法,但通用寄存器的数量还不够

Is there any way to use the special registers (eip, eflags) as general purpose registers in asm?有什么方法可以将特殊寄存器(eip、eflags)用作 asm 中的通用寄存器?

I need them only for a few operations but all general registers are already occupied, I do not like to store values ​​in memory that would decrease the performance of the algorithm.我只需要它们进行一些操作,但所有通用寄存器都已被占用,我不喜欢将值存储在内存中,这会降低算法的性能。

Is it possible?是否可以?

Judicious reuse of the general purpose registers already available to you is likely to be your best bet.明智地重用您已经可用的通用寄存器可能是您最好的选择。 Think very carefully about your algorithm.仔细考虑你的算法。

Repurposing EIP isn't possible and using EFLAGS for something else, while perhaps possible, just has too many side effects to be generally useful.重新利用 EIP 是不可能的,并且将 EFLAGS 用于其他用途,虽然可能是可能的,但副作用太多而无法普遍使用。

Better would be to actually time your algorithm using memory.更好的是使用内存对算法进行实际计时。 You may find that because of cacheing, the access is not as slow as you might have thought.您可能会发现由于缓存的原因,访问并不像您想象的那么慢。

Another option is to use the math coprocessor's register as simply a small private stack for storage, but this, too is likely to be less satisfactory than simply using memory.另一种选择是将数学协处理器的寄存器用作简单的小型私有堆栈用于存储,但这也可能不如简单地使用内存令人满意。

Short answer : No. Those registers aren't meant to be written to explicitly.简短回答:不。这些寄存器并不意味着要明确写入。

You'd have to either rewrite your algorithm, better allocate your registers, deal with intelligently spilling/reloading registers to memory to minimize performance impact or, if possible, use XMM registers to either move INT registers to/from, or do chains of instruction all on the XMM side.你要么重写你的算法,更好地分配你的寄存器,处理智能地将寄存器溢出/重新加载到内存以最小化性能影响,或者,如果可能的话,使用 XMM 寄存器来移动 INT 寄存器或执行指令链一切都在 XMM 方面。 Another option is to use 64bit to utilize the extra registers made available.另一种选择是使用 64 位来利用可用的额外寄存器。

The short answer is no.最简洁的答案是不。

If you are running a program, using eip as a general purpose register is definitely not possible as if you do "write" to eip, your program will jump into running instructions at that address (roughly), which will probably not work.... As for EFLAGS, it has a number of bits that are either reserved or control various things you dont want changing, meaning again, it will not work as a general purpose register.如果您正在运行一个程序,那么使用 eip 作为通用寄存器是绝对不可能的,就像您对 eip 进行“写入”一样,您的程序将跳转到该地址处的运行指令(大致),这可能不起作用...... . 至于EFLAGS,它有许多位可以保留或控制您不想更改的各种事物,这再次意味着它不能作为通用寄存器工作。 As you seem to be intent on not using memory to retain values, you could use esp and ebp (being careful if you are at all using the stack).由于您似乎不打算使用内存来保留值,因此您可以使用 esp 和 ebp (如果您完全使用堆栈,请小心)。 Other than that, most of the registers I can think you using require permission level 0 to write to and again, would have very likely negative consequences if you were to use them as general purpose registers.除此之外,我认为您使用的大多数寄存器都需要 0 级权限才能写入和再次写入,如果您将它们用作通用寄存器,则很可能会产生负面影响。

There MIGHT be some very special registers that are specific to your processor, but the code would not be portable between processors if you were to use them.可能有一些特定于您的处理器的非常特殊的寄存器,但是如果您要使用它们,代码将无法在处理器之间移植。

I remember that i used the debug register dr0 to dr3 for storing data.我记得我使用调试寄存器 dr0 到 dr3 来存储数据。 But i am not sure how fast they are to use.但我不确定他们使用的速度有多快。 Maybe the register renaming inside the CPU(for to build micro ops) let it be performant too.也许 CPU 内部的寄存器重命名(用于构建微操作)也让它具有高性能。

Register File is small storage that provides support to just one instruction and is used for intermediate computations.寄存器文件是一种小型存储,仅支持一条指令,用于中间计算。 And if you want to extensively use registers, it would kill the purpose of having fast storage such as the registers.如果你想广泛使用寄存器,它会破坏拥有快速存储(如寄存器)的目的。

On the other hand, CACHEs are built for the 2nd level of the memory hierarchy that you would like to use.另一方面,缓存是为您想要使用的内存层次结构的第二级构建的。 Therefore you need to design algorithms that take full benefit of data locality that are favored by these CACHEs.因此,您需要设计算法来充分利用这些缓存所支持的数据局部性。 There are separate caches for instructions that reuse instruction, such as in loops, which are very efficiently implemented.有单独的高速缓存用于重用指令的指令,例如在循环中,这非常有效地实现。

Even then if one wants to use registers intensively, then intelligent compilers are another option in which case intelligent register allocation techniques are used.即使这样,如果想要集中使用寄存器,那么智能编译器也是另一种选择,在这种情况下,使用智能寄存器分配技术。 A recent hybrid technique uses an off-line machine learning algorithm to build a heuristic function (which is used in run-time) that determines and switches between different allocation methods that will perform better in light of code behavior.最近的一种混合技术使用离线机器学习算法来构建启发式函数(在运行时使用),该函数根据代码行为确定和切换不同的分配方法,这些方法将执行得更好。 I hope it helped.我希望它有所帮助。 Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM