flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > converting 64-bit registers into 32-bit registers

Author
Thread Post new topic Reply to topic
Hugh Aguilar



Joined: 15 Nov 2011
Posts: 62
Location: Arizona
Hugh Aguilar 09 Mar 2013, 01:43
I wrote this macro:

macro clr reg
{
xor reg, reg
}

If reg is a 64-bit register, I would like the macro to compile for the 32-bit version of that register.

For example:

clr rcx

would compile as:

xor ecx, ecx

The end result is that RCX gets zeroed as 32-bit instructions automatically zero out the upper 32-bits, but I would save a byte in memory because the REX prefix byte wouldn't need to be compiled. It might be slightly faster also.
Post 09 Mar 2013, 01:43
View user's profile Send private message Send e-mail Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 09 Mar 2013, 01:49
One option would be to reverse the following macro:
http://board.flatassembler.net/topic.php?p=98098#98098
Post 09 Mar 2013, 01:49
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Mar 2013, 08:01
Hugh Aguilar,

There are several methods, I've thought about somewhat indirect one:
Code:
macro clr reg* {
  irps suffix, ax cx dx bx sp bp si di \{ r\#suffix equ e\#suffix \}
  xor reg, reg
  restore rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi
}    
Post 09 Mar 2013, 08:01
View user's profile Send private message Reply with quote
Hugh Aguilar



Joined: 15 Nov 2011
Posts: 62
Location: Arizona
Hugh Aguilar 13 Mar 2013, 04:50
baldr wrote:
Hugh Aguilar,

There are several methods, I've thought about somewhat indirect one:
Code:
macro clr reg* {
  irps suffix, ax cx dx bx sp bp si di \{ r\#suffix equ e\#suffix \}
  xor reg, reg
  restore rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi
}    


I will give that a try. This won't work for the upper registers as they have a different syntax (R13 vs R13D rather than RBP vs EBP), but I may be able to upgrade it. If not, I may be able to get by with only the lower registers.

I thought I remembered a simple way to do this, but I searched the FASM manual and couldn't find it. I may have been remembering NASM or HLA --- learning more than one assembler at a time has resulted in a mismatched jumble of information in my head! Confused

For the most part, FASM is working out well for me --- I haven't run into much that it couldn't do. Smile
Post 13 Mar 2013, 04:50
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 13 Mar 2013, 05:11
Hugh Aguilar,

There's no reason to use it for r8d…r15d — their usage requires REX prefix too (though slightly different one).
Post 13 Mar 2013, 05:11
View user's profile Send private message Reply with quote
Hugh Aguilar



Joined: 15 Nov 2011
Posts: 62
Location: Arizona
Hugh Aguilar 13 Mar 2013, 06:55
baldr wrote:
Hugh Aguilar,

There's no reason to use it for r8d…r15d — their usage requires REX prefix too (though slightly different one).


Good point. I'll go with what you provided. Thanks.
Post 13 Mar 2013, 06:55
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.