简体   繁体   English

使用 FPU 和 MMX 寄存器作为“通用寄存器”

[英]Using FPU and MMX registers as “general registers”

Most assembly programs make use of the 4 general purpose registers eax ebx ecx edx but I find that quite often I need to use more than 4 registers to accomplish my task easily without having to push and pop from the stack to much.大多数汇编程序使用 4 个通用寄存器eax ebx ecx edx但我发现我经常需要使用 4 个以上的寄存器来轻松完成我的任务,而不必从堆栈中pushpop太多。 Since my program has no intentions of using the FPU or MMX registers for floating point calculations or their "intended use", is it considered acceptable to use these extra registers in your program?由于我的程序无意使用 FPU 或 MMX 寄存器进行浮点计算或其“预期用途”,在您的程序中使用这些额外的寄存器是否可以接受?

Eg.例如。 using xmm0 for a loop increment counter freeing up the ecx register to do other things.使用xmm0作为循环增量计数器释放ecx寄存器来做其他事情。

Why four?为什么是四个? You can use all of these: eax , ebx , ecx , edx , esi , edi and ebp .您可以使用所有这些: eaxebxecxedxesiediebp That's seven.那是七。 Or is that not enough either?或者这还不够?

FPU and MMX registers are somewhat awkward to work with since they can only be loaded from themselves and memory and stored only to themselves and memory. FPU 和 MMX 寄存器使用起来有些笨拙,因为它们只能从自身和内存中加载,并且只能存储到自身和内存中。 You cannot freely move data between them and general purpose registers, nor there are instructions capable of operating on both kinds of registers at the same time.您不能在它们和通用寄存器之间自由移动数据,也没有能够同时对两种寄存器进行操作的指令。

If seven general purpose registers aren't enough, use local/on-stack variables.如果七个通用寄存器不够,请使用本地/堆栈变量。 For example, you can decrement a counter variable in memory directly and you can also directly compare it with a constant or another register.例如,您可以直接递减内存中的计数器变量,也可以直接将其与常量或其他寄存器进行比较。 Chances are, this is going to be no slower (likely, faster) than using FPU or MMX registers in strange ways.很有可能,这不会比以奇怪的方式使用 FPU 或 MMX 寄存器慢(可能,更快)。

How often do you need full 32 bits of a register?您多久需要一个完整的 32 位寄存器? For things like small counters, feel free to use byte-sized quarters of general purpose registers: AH/AL, BH/BL, CH/CL, DH/DL.对于小计数器之类的东西,可以随意使用字节大小的四分之一通用寄存器:AH/AL、BH/BL、CH/CL、DH/DL。 With some bitwise trickery, you can also use upper 16 bits of general purpose registers as an intermediate storage for word-sized variables.通过一些按位技巧,您还可以使用通用寄存器的高 16 位作为字大小变量的中间存储。

In real mode (read: under DOS), you can also use segment registers ES, FS, and GS for intermediate value storage.在实模式下(读:DOS下),还可以使用段寄存器ES、FS和GS进行中间值存储。 Under a protected-mode OS (Windows, Linux, *nix) the code will crash, though.但是,在保护模式操作系统(Windows、Linux、*nix)下,代码会崩溃。

好吧,当然也有 SI 和 DI,在 x64 上你有额外的寄存器,但你可以根据需要使用 FP 寄存器。

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

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