News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

trash ecx or edx?

Started by jj2007, May 28, 2008, 11:17:42 AM

Previous topic - Next topic

jj2007

Quick poll: If you write a macro that uses two registers, then one is EAX, sure, but which one would you choose as No. 2 if you cannot afford a push/pop? ECX or EDX?

hutch--

jj,

by spec, you can trash any of eax ecx edx are not required to be preserved. If it in the middle of a critical algo, I would see if you have another register which may be either of these or any of the others that is repeatedly overwritten with new data AFTER you have run the macro you may be able to use that instead. If you lay out the algo carefully you can often get a couple of extra registers this way.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Hutch, what you say is perfectly correct but that was not my question. Imagine you have a big fat project, and you need that macro pretty often. And you don't want to insert all the time a push/pop. In my fattest source, I use 142 times edx, and 444 times ecx, so edx would be a better choice because it's more rarely used.
Remember the abs macro thread. Surely there were macros that were just a little bit faster, but at the expense of having to sacrifice an extra register. No good for a general purpose macro, especially since many people have so much trust in Sir Hutch's macros that they would blindly write mov MyVar, abs(edx)...

Tedd

I'd consider edx as a secondary data register -- in the same way that mul and div do
No snowflake in an avalanche feels responsible.

hutch--

jj,

You could try a local or even a data? section variable so you can use MOV rather than PUSH/POP as it is almost exclusively faster.


.data?
  _edx dd ?

.code
  ......
  mov _edx, edx
    ; use EDX for something
  mov edx, _edx
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php