NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: Patrick Horgan on October 23, 2008, 08:16:12 PM

Title: Choose op format for op with direction bit?
Post by: Patrick Horgan on October 23, 2008, 08:16:12 PM
For an add edx, ecx for example in 32 bit mode, you could get 01CA or 03D1 with different direction bit and with the register designators swapped.  For bizarre reasons I'd like it to use the 03D1 version, but nasm generates the other even though it understands both from ndisasm.  Is there any way to specify that on this and other register to register with direction bit instructions that the source should be on the right?

Patrick
phorgan1@gmail.com (http://mailto:phorgan1@gmail.com)
Title: Re: Choose op format for op with direction bit?
Post by: Frank Kotler on October 27, 2008, 09:49:55 PM
Hi Patrick,

I don't think there's any "easy" way to do it. If you've only got a couple instances, easiest thing might be to just stuff the proper "db"s in. Possibly a macro could be constructed to do it(?).

Unless I'm mistaken, Nasm will assemble the first form it encounters in insns.dat. If you were to swap the two instances of "ADD REG32, REG32" you'll find in insns.dat and recompile Nasm (needs PERL), I *think* Nasm would assemble "the other one". Whether it would be worthwhile to do this throughout (I don't even know which instructions have such forms)... depends on how bad you need it, I guess. :)

Best,
Frank
Title: Re: Choose op format for op with direction bit?
Post by: nobody on October 28, 2008, 10:01:26 AM
> For an add edx, ecx for example in 32 bit
> mode, you could get 01CA or 03D1 with
> different direction bit and with the register
> designators swapped. For bizarre reasons

Your "bizarre" reasons are very well known, as well as the problem. If you switch your assembler  (MASM->FASM, TASM->NASM, ...), you'll get 90% of instructions encoded differently. "db" is your friend, Intel isn't :-D