How to resolve ambivalence in x64 assembly?

Viewed 98

I'm writing an assembler. I always thought that assembly had a 1:1 correspondence between a certain assembly instruction and corresponding instruction, so I thought it would be fairly easy to write one. But after actually reading the Intel 64 Software Dev Manual, I now realize that a command like

mov %rdx,%rbx

has a certain ambivalence to it. It could be translated to 48 89 D3 which corresponds to

REX.W + 89 /r - MOV r64,r/m64

from page 1235 of the Intel 64 Software Dev Manual.

But it could also be translated to 48 8B DA (REX.W + 8B /r - MOV r/m64,r64).

This is the output from a disassembly by objdump -d of the binary:

0:  48 89 d3                mov    %rdx,%rbx
3:  48 8b da                mov    %rdx,%rbx

By reading the manual it is pretty obvious why this ambivalence exists. There are a handful of cases where there is ambivalence like this.

I have tested the code in some instances and it performed exactly the same.

Is there a benefit of using the one over the other (gnu assembler uses 48 89 D3 in all cases I looked at) or should I just pick one of them at random?

0 Answers
Related